Android: Draw a bitmap on top of another, matrix applied
I have an imageview, which uses matrix to scale/drag an image. Now I want to overlay another image. The matrix transformation should be applied to the combination of background and overlay.
I did overwrite onDraw and used
canvas.drawBitmap(overlay, matrix, null);
whereas overlay is the new overlay, matrix is the currently applied matrix. This works fine. Unfortunately I can't specify an offset at which the overlay shall appear on top of the background. This works
canvas.drawBitmap(overlay, 50, 10, null);
but the overlay remains on that position, once I draw and scale the bac开发者_高级运维kground again...
How can I accomplish an offset while drawing a bitmap with matrix applied?
Regards
You may need to create a new bitmap of approprite size where your overlay will be saved with the matrix transformation. Something like:
Bitmap overlay2 = Bitmap.createBitmap(....)
Canvas c2 = new Canvas(overlay2);
c2.drawBitmap(overlay, matrix, null);
canvas.drawBitmap(overlay2, 50, 10, null);
The other way perhaps better is to do canvas.translate:
canvas.save();
canvas.translate(50,10);
canvas.drawBitmap(overlay, matrix, null);
canvas.restore();
精彩评论