Contents

조회 수 60741 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
537 Develop [c] 텍스트 파일(로그)을 정해진 라인 단위로 쪼개주는 코드 file hooni 2013.04.23 7046
536 Develop [c] 네트워크 트래릭 모니터링.. 졸업작품.. 2 file hooni 2013.04.23 11047
535 Develop [c#] MS IE(Internet Explorer) 툴바 버튼 예제 2003/2005 두가지 버전 secret hooni 2013.04.23 2090
534 Develop [c#] BFilter 툴바 소스 코드 ㅎㅎ file hooni 2013.04.23 7606
533 Develop [c++] mfc로 만든 현재 디렉토리 읽어오기/세팅하기 (GetCurrentDirectory/SetCurrentDirectory) file hooni 2013.04.23 8465
532 Develop 다운 받아서 테스트 해볼것.. hooni 2013.04.23 9139
531 Develop [c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일 file hooni 2013.04.23 7052
530 Develop [c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드 2 hooni 2013.04.23 15330
529 Develop [c] kmp 활용 search file hooni 2013.04.23 7416
528 Develop [c] 문자열 str_shift 예제.. file hooni 2013.04.23 6839
527 Develop [c++] winsock을 이용한 서버,클라이언트와 ssl서버,클라이언트 file hooni 2013.04.23 7610
526 Develop [c++] mfc이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트 file hooni 2013.04.23 9249
Board Pagination Prev 1 ... 49 50 51 52 53 54 55 56 57 58 ... 98 Next
/ 98