Develop
2013.04.23 16:50
[android] Canvas를 이용해 이미지 확대/축소 하기
조회 수 60744 댓글 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); } } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
645 | Develop | [asp] 문자열 관련 함수 요약 | hooni | 2013.04.23 | 7780 |
644 | Develop | [jsp] HelloServlet 출력문 | hooni | 2003.04.23 | 7794 |
643 | Develop | [mysql] 양력, 음력 DB데이터 | hooni | 2013.04.23 | 7802 |
642 | Develop | [c] 이진트리(binary tree) 샘플소스 (삽입, 삭제, 운행) | hooni | 2003.04.23 | 7807 |
641 | Develop | [c] 소수 구하기 #1 (한정된 숫자 내에 있는 소수 걸러내기) | hooni | 2003.04.23 | 7811 |
640 | Develop | [c] fgets() 함수 사용하기.. | hooni | 2003.04.23 | 7819 |
639 | Develop | [c] i2osp 임시로.. ㅋㅋ | hooni | 2003.04.23 | 7819 |
638 | Develop | [linux] 프로세스 관련 시스템콜 | hooni | 2003.04.23 | 7827 |
637 | Develop | [java] RGB 색상 조절 버튼.. 스윙(swing) | hooni | 2013.04.23 | 7835 |
636 | Develop | [c] OpenGL 색 입방체의 회전(입체) | hooni | 2003.04.23 | 7869 |
635 | Develop | [java] 마우스 버튼 테스트.. swing.. | hooni | 2013.04.23 | 7888 |
634 | Develop | [js] 자바스크립트 이벤트 핸들.. | hooni | 2003.04.23 | 7908 |