Views 60741 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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

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 •
?

  1. [android] 개발 환경 세팅 따라하기 ㅋㅋ

  2. [android] 단일 Thread 환경의 안드로이드에서 Handler를 사용

  3. [android] 디바이스(시뮬레이터) hosts 파일 수정하기

  4. [android] 딜레이를 구현하기 위한 꼼수

  5. [android] 레이아웃 사이즈 변경 (동적; programmatically)

  6. [android] 만화 어플 소스코드

  7. [android] 멀티터치(Multi touch) 부분 구현 ㅋㅋ

  8. [android] 버전 별 앱 알림 설정으로 이동하는 방법

  9. [android] 안드로이드 동영상 스트리밍 예제

  10. [android] 안드로이드 앱 문서 샘플 - NCComix

  11. [android] 안드로이드 어플 모음 ㅎㅎ

  12. [android] 자동차 리모컨 소스코드

  13. [android] 점심 해결 앱 소스 코드 ㅋㅋ

  14. [Android] 제스처 자료..

  15. [android] 초간단 HTTP, POST 전송 샘플

  16. [android] 초간단 얼럿 (AlertDialog)

Board Pagination Prev 1 4 5 6 7 8 ... 74 Next
/ 74