Contents

조회 수 60746 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

캔버스를 이용해 이미지 확대/축소하는 코드

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);
        }
    }
}

TAG •

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
777 Develop [ios] 최신 UI 모음.. (나중에 정리할 것) secret hooni 2013.08.09 0
776 Develop [ios] UI컨트롤러 샘플코드 hooni 2013.08.08 15425
775 Develop [ios] libxml/tree.h file not found file hooni 2013.08.08 18709
774 Develop [ios] 소소한 팁 (Rect,Point,Path,URL 등) hooni 2013.08.08 29457
773 Develop [ios] Background 에서 네트워크 사용 file hooni 2013.07.22 11510
772 Develop [ios] App States file hooni 2013.07.22 13195
771 Etc 영어의 12 시제 (The twelve tenses of English) hooni 2013.07.12 15702
770 System/OS [mac] 컨텍스트(Context) 메뉴 "다음으로 열기" 내용 정리 hooni 2013.07.10 18798
769 Develop git 브런치 배우기 (링크) hooni 2013.07.09 20571
768 Develop GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기) 4 file hooni 2013.07.06 25316
767 Develop GCM 사용하기 2 (단말에 GCM 구현하기) file hooni 2013.07.06 23248
766 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51356
Board Pagination Prev 1 ... 29 30 31 32 33 34 35 36 37 38 ... 98 Next
/ 98