Sam Berg Sam Berg - 1 year ago 83
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.



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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download