dimanche 29 mars 2015

Android: Using Canvas to draw on top of a bitmap

So I have a bitmap (called imgBitmap) that is displayed in a custom imageview. When the user double clicks, I want a circle to appear on top of the image where they are clicking. With the following code, the original bitmap gets deleted and there is just a circle on the screen. How do I make it so the circle is drawn but the original bitmap is still there?



@Override
public boolean onDoubleTap(MotionEvent event) {


Bitmap bmOverlay = Bitmap.createBitmap(getWidth(),
getHeight(),
imgBitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
Paint p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStrokeWidth(2);
p.setStyle(Paint.Style.STROKE);
canvas.drawBitmap(bmOverlay, matrix, background);
canvas.drawCircle((int)event.getX(),(int)event.getY(),
15, p);
setImageBitmap(bmOverlay);
return true;
}


@Override
public boolean onDown(MotionEvent e) {
return false;
}
}

Aucun commentaire:

Enregistrer un commentaire