1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | public class MainActivity extends Activity implements OnTouchListener { ImageView imageView; Bitmap bitmap; Canvas canvas; Paint paint; float bx = 0; float by = 0; float dx = 0; float dy = 0; float ex = 0; float ey = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); Display currentDisplay = getWindowManager().getDefaultDisplay(); float dw = currentDisplay.getWidth(); float dh = currentDisplay.getHeight(); bitmap = Bitmap.createBitmap((int) dw, (int) dh,Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); paint = new Paint(); paint.setColor(Color.BLACK); imageView = new ImageView(this); imageView.setImageBitmap(bitmap); imageView.setOnTouchListener(this); setContentView(imageView); } public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: bx = event.getX(); by = event.getY(); break; case MotionEvent.ACTION_MOVE: canvas.drawLine(bx, by, event.getX(), event.getY(), paint); imageView.invalidate(); bx = event.getX(); by = event.getY(); break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION_CANCEL: break; default: break; } return true; } } |
Thursday, September 13, 2012
touch draw on Bitmap (android)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment