Sam Berg Sam Berg - 20 days ago 9
Android Question

How to overlay a bitmap over another

I have tried the solution suggested here Android: How to overlay-a-bitmap/draw-over a bitmap?. I seems to work but I obtained a slightly disoriented image from it.

before-overlay

after-overlay

enter image description here
enter image description here

I have set my edit icon to toggle between start and stop drawing on canvas. When the user stops drawing, I retrieve the canvas bitmap and the imageView and overlay canvas bitmap on the imageView.
As can be seen from the screenshots, the imageView is the laptop image and canvas bitmap is the up arrow I drew.
Here is my overlay function.

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, new Matrix(), null);
return bmOverlay;
}


I am new to android and would appreciate some help in this regard.
Thanks!

Answer

i think you can use something like this to achieve what you want :

Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
Canvas result = new Canvas(underlayBitmap);
result.drawBitmap(overlayBitmap, left, top, paint);

you can give the top side and left side where you want your overlay to be drawn.

hope this helps.