Skip to main content

In my imageview I want to draw a bitmap everytime imageview is touched without erasing the previous bitmap. Below code draws a new bitmap but also erases the previous one. How can I keep the previous bitmap while adding new one? Thanks

imageview.setOnTouchListener(new View.OnTouchListener() {   @Override   public boolean onTouch(View v, MotionEvent event) {   int action = event.getAction();   x = event.getX();   y = event.getY();   switch (action) {     case MotionEvent.ACTION_DOWN:   Bitmap.Config config = bm.getConfig();   int width = bm.getWidth();   int height = bm.getHeight();   Bitmap bm2 = Bitmap.createBitmap(width, height, config);   Canvas c = new Canvas(bm2);   c.drawBitmap(bm, 0, 0, null);   Bitmap repeat = BitmapFactory.decodeResource(getResources(), R.drawable.pic);   Bitmap repeat2 = Bitmap.createScaledBitmap(repeat, 50, 50, false);     c.drawBitmap(repeat2, x, y, p);     imageview.setImageBitmap(bm2);     break;     return true; }   });    } 

Like this image

In my imageview I want to draw a bitmap everytime imageview is touched without erasing the previous bitmap. Below code draws a new bitmap but also erases the previous one. How can I keep the previous bitmap while adding new one? Thanks

imageview.setOnTouchListener(new View.OnTouchListener() {   @Override   public boolean onTouch(View v, MotionEvent event) {   int action = event.getAction();   x = event.getX();   y = event.getY();   switch (action) {   case MotionEvent.ACTION_DOWN:   Bitmap.Config config = bm.getConfig();   int width = bm.getWidth();   int height = bm.getHeight();   Bitmap bm2 = Bitmap.createBitmap(width, height, config);   Canvas c = new Canvas(bm2);   c.drawBitmap(bm, 0, 0, null);   Bitmap repeat = BitmapFactory.decodeResource(getResources(), R.drawable.pic);   Bitmap repeat2 = Bitmap.createScaledBitmap(repeat, 50, 50, false);     c.drawBitmap(repeat2, x, y, p);     imageview.setImageBitmap(bm2);     break;     return true; }   });    } 

Like this image

In my imageview I want to draw a bitmap everytime imageview is touched without erasing the previous bitmap. Below code draws a new bitmap but also erases the previous one. How can I keep the previous bitmap while adding new one? Thanks

imageview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); x = event.getX(); y = event.getY(); switch (action) {    case MotionEvent.ACTION_DOWN: Bitmap.Config config = bm.getConfig(); int width = bm.getWidth(); int height = bm.getHeight(); Bitmap bm2 = Bitmap.createBitmap(width, height, config); Canvas c = new Canvas(bm2); c.drawBitmap(bm, 0, 0, null); Bitmap repeat = BitmapFactory.decodeResource(getResources(), R.drawable.pic); Bitmap repeat2 = Bitmap.createScaledBitmap(repeat, 50, 50, false); c.drawBitmap(repeat2, x, y, p); imageview.setImageBitmap(bm2); break; return true; } }); } 

Like this image

Source Link
artist
  • 6.4k
  • 8
  • 28
  • 37

Draw bitmap on imageview with every touch - android

In my imageview I want to draw a bitmap everytime imageview is touched without erasing the previous bitmap. Below code draws a new bitmap but also erases the previous one. How can I keep the previous bitmap while adding new one? Thanks

imageview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); x = event.getX(); y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: Bitmap.Config config = bm.getConfig(); int width = bm.getWidth(); int height = bm.getHeight(); Bitmap bm2 = Bitmap.createBitmap(width, height, config); Canvas c = new Canvas(bm2); c.drawBitmap(bm, 0, 0, null); Bitmap repeat = BitmapFactory.decodeResource(getResources(), R.drawable.pic); Bitmap repeat2 = Bitmap.createScaledBitmap(repeat, 50, 50, false); c.drawBitmap(repeat2, x, y, p); imageview.setImageBitmap(bm2); break; return true; } }); } 

Like this image