2008년 5월 25일 일요일

소스입니다.

 소스입니다.
 좀 허접해서 창피하지만 도움 되었으면 좋겠습니다.
 칼라부분이 수정또는 추가 된 부분이고요 녹색부분은 삭제해도 잘 돌아 가요..
 나중에 좋은 결과있으시면 소주한잔 사세요...ㅎㅎㅎㅎㅎ
 
 아 그리고 "손맛"  영어로 어떻게 표현하면 좋을까요? 이글 보시는 분들 지발 좀 답 좀 주세요..


 


package com.google.android.samples.graphics;


import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;


//Need the following import to get access to the app resources, since this
//class is in a sub-package.



/**
 * Demonstrates the handling of touch screen events to implement a simple
 * painting app.
 */
public class TouchPaint extends Activity {   
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(new MyView(this));
    }
   
    public class MyView extends View {
        Bitmap mBitmap;
        Canvas mCanvas;
        private final Rect mRect = new Rect();
        private final Paint mPaint;
        private boolean mCurDown;
        private int mCurX;
        private int mCurY;
        private int mOCurX=0;
       private int mOCurY=0;

        private float mCurPressure;
        private float mCurSize;
        private int mCurWidth;
       
        public MyView(Context c) {
            super(c);
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
            mPaint.setARGB(255, 255, 255, 255);
        }


        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
            int curW = mBitmap != null ? mBitmap.width() : 0;
            int curH = mBitmap != null ? mBitmap.height() : 0;
            if (curW >= w && curH >= h) {
                return;
            }
           
            if (curW < w) curW = w;
            if (curH < h) curH = h;
           
            Bitmap newBitmap = Bitmap.createBitmap(curW, curH, false);
            Canvas newCanvas = new Canvas();
            newCanvas.setDevice(newBitmap);
            if (mBitmap != null) {
                newCanvas.drawBitmap(mBitmap, 0, 0, null);
            }
            mBitmap = newBitmap;
            mCanvas = newCanvas;
        }
       
        @Override
        protected void onDraw(Canvas canvas) {
            if (mBitmap != null) {
                canvas.drawBitmap(mBitmap, 0, 0, null);
            }
        }


    
 
  @Override
        public boolean onMotionEvent(MotionEvent event) {
            int action = event.getAction();
            mCurDown = action == MotionEvent.ACTION_DOWN
                    || action == MotionEvent.ACTION_MOVE;
            mCurX = (int)event.getX();
            mCurY = (int)event.getY();
            if(action == MotionEvent.ACTION_DOWN  && action != MotionEvent.ACTION_MOVE){
                 mOCurX =mCurX;
                 mOCurY =mCurY;
            }

        
           
            mCurPressure = event.getPressure();
            mCurSize = event.getSize();
            mCurWidth = (int)(mCurSize*(getWidth()/3));
            if (mCurWidth < 1) mCurWidth = 1;
            if (mCurDown && mBitmap != null) {
                int pressureLevel = (int)(mCurPressure*255);
                mPaint.setARGB(pressureLevel, 0, 255, 255);
              //mCanvas.drawCircle(mCurX, mCurY, mCurWidth, mPaint);
                mCanvas.drawPoint(mCurX, mCurY,  mPaint);
                mCanvas.drawLine(mOCurX, mOCurY, mCurX, mCurY,mPaint);
                mOCurX =mCurX;
                mOCurY =mCurY;

               
              //  mRect.set(mCurX-mCurWidth-2, mCurY-mCurWidth-2,
              //          mCurX+mCurWidth+2, mCurY+mCurWidth+2);
                
              //invalidate(mRect);
                 invalidate();
            }
            return true;
        }
       
    }
}



동영상

댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby