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); } } }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
12 | Develop | [ios] Facebook Cache 갱신하는 함수 | hooni | 2017.02.27 | 1186 |
11 | Develop | [ios] 동영상 플레이어 샘플 (for PIP Player) | hooni | 2017.03.15 | 1266 |
10 | Develop | Mac OS 에 Jenkins 설치하기 (Homebrew) 2 | hooni | 2017.03.15 | 8114 |
9 | Develop | [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법 | hooni | 2017.03.29 | 953 |
8 | Database | [mysql] 쿼리 실행시 ERROR 1366 (HY000) : incorrect string value : for column 3 | hooni | 2017.03.30 | 8787 |
7 | Develop | [ios] NSString, RegularExpression Find/Replace | hooni | 2017.04.14 | 843 |
6 | Develop | [ios] Facebook SDK 로그인 설명 | hooni | 2017.04.19 | 1164 |
5 | System/OS | [linux] 초간단 Postfix, Covecot, SSL/TLS (SMTP) | hooni | 2017.12.11 | 9335 |
4 | Database | [mysql] ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. | hooni | 2017.12.15 | 1207 |
3 | Develop | [ios] Requesting Location Permissions in iOS | hooni | 2018.08.18 | 1606 |
2 | System/OS | 서버 확장을 위한 두 가지 방법 | hooni | 2018.08.29 | 2105 |
1 | System/OS | 맥에서 포트 확인하고 닫기 (mac) | hooni | 2022.03.22 | 902 |