Develop
2013.04.23 16:50
[android] Canvas를 이용해 이미지 확대/축소 하기
조회 수 60721 댓글 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); } } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
841 | Develop | [ios] 아이폰용 앱 오픈 소스들 | hooni | 2013.04.23 | 465032 |
840 | Develop | [ios] 언어, 지역, 국가 설정 가져오기 | hooni | 2014.05.12 | 268596 |
839 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 267121 |
838 | Develop | [ios] Start developing your navigation app for CarPlay without enrollment | hooni | 2020.02.22 | 124379 |
837 | Develop | [android] 만화 어플 소스코드 | hooni | 2013.04.23 | 92832 |
836 | Develop | 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 | hooni | 2013.04.23 | 81369 |
835 | Develop | [c#] Hashtable <-> Json (dll 포함) | hooni | 2013.04.23 | 80644 |
834 | Develop | [C#] MD5, SHA1 해시 & 인코딩 | hooni | 2013.04.23 | 77849 |
833 | Develop | [android] 점심 해결 앱 소스 코드 ㅋㅋ | hooni | 2013.04.23 | 76390 |
832 | Develop | [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드) | hooni | 2013.04.23 | 71968 |
831 | Develop | [android] keytool을 사용하여 키스토어 생성 | hooni | 2013.04.23 | 69500 |
830 | Develop | [ios] Random Thoughts: Rand() vs. arc4random() | hooni | 2013.10.31 | 68018 |