Contents

조회 수 60800 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
321 Develop [c] 문자열 처리(문자열 자르기) hooni 2003.04.23 8667
320 Develop [c] 문자열 처리 관련 함수들 설명 hooni 2003.04.23 8017
319 Develop [c] 문자열 정렬 함수 qsort() hooni 2003.04.23 8277
318 Develop [c] 문자열 자르는 함수(strtok) 예제 hooni 2013.04.23 12228
317 Develop [c] 문자열 라이브러리 최신버전 file hooni 2003.04.23 7225
316 Develop [c] 문자열 뒤집기 초간단 샘플 코드 ㅎㅎ hooni 2013.04.23 7136
315 Develop [c] 문자열 뒤집기 (문자열 거꾸로 출력하는 간단소스) hooni 2003.04.23 10061
314 Develop [c] 문자열 str_shift 예제.. file hooni 2013.04.23 6862
313 Develop [c] 무선 Radius Server 자료.. file hooni 2013.04.23 7284
312 Develop [c] 메시지큐(Message Queue) 설명.. (joinc) hooni 2013.04.23 14310
311 Develop [c] 메세지 프로그램 (Server - Agent - Client) file hooni 2013.04.23 6481
310 Develop [c] 맵서치인 듯(옛날 컴에서 찾은 자료) file hooni 2013.04.23 6920
Board Pagination Prev 1 ... 67 68 69 70 71 72 73 74 75 76 ... 98 Next
/ 98