Develop
2013.04.23 16:50
[android] Canvas를 이용해 이미지 확대/축소 하기
조회 수 60746 댓글 0
캔버스를 이용해 이미지 확대/축소하는 코드
import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Rect; import android.os.Bundle; import android.view.View; import android.view.Window; public class CanvasView extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(new ImageView(this)); } public class ImageView extends View{ private Bitmap image; // 이미지 public ImageView(Context context) { super(context); setBackgroundColor(Color.WHITE); // 그림 읽어들이기 Resources r = context.getResources(); image = BitmapFactory.decodeResource(r, R.drawable.excavator); } @Override protected void onDraw(Canvas canvas) { // 원본이미지 canvas.drawBitmap(image, 0, 0, null); // 원본이미지 영역을 축소해서 그리기 int w = image.getWidth(); int h = image.getHeight(); Rect src = new Rect(0, 0, w, h); Rect dst = new Rect(0, 200, w / 2, 200 + h / 2); canvas.drawBitmap(image, src, dst, null); super.onDraw(canvas); } } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
537 | Develop | [java] RGB 색상 조절 버튼.. 스윙(swing) | hooni | 2013.04.23 | 7837 |
536 | Develop | [linux] 프로세스 관련 시스템콜 | hooni | 2003.04.23 | 7827 |
535 | Develop | [c] i2osp 임시로.. ㅋㅋ | hooni | 2003.04.23 | 7821 |
534 | Develop | [c] fgets() 함수 사용하기.. | hooni | 2003.04.23 | 7819 |
533 | Develop | [c] 소수 구하기 #1 (한정된 숫자 내에 있는 소수 걸러내기) | hooni | 2003.04.23 | 7811 |
532 | Develop | [c] 이진트리(binary tree) 샘플소스 (삽입, 삭제, 운행) | hooni | 2003.04.23 | 7807 |
531 | Develop | [mysql] 양력, 음력 DB데이터 | hooni | 2013.04.23 | 7802 |
530 | Develop | [jsp] HelloServlet 출력문 | hooni | 2003.04.23 | 7796 |
529 | Develop | [asp] 문자열 관련 함수 요약 | hooni | 2013.04.23 | 7780 |
528 | Develop | [c] 근의 공식으로 2차방정식 풀기.. | hooni | 2003.04.23 | 7775 |
527 | Develop | [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 | hooni | 2003.04.23 | 7771 |
526 | Develop | [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 | hooni | 2003.04.23 | 7770 |