Reputation: 189
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.
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!
Upvotes: 2
Views: 3629
Reputation: 635
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.
Upvotes: 3
Reputation: 1092
The most easier way to do that without go deeper with graphics libs is using FrameLayout, with this layout you can place one view above the other in order as they are added to the layout, example:
<FrameLayout>
<ImageView android:id="@+id/imageView1" />
<ImageView android:id="@+id/imageView2" />
</FrameLayout>
In example above imageView2 will overlap imageView1, this is so far the fastest way to overlay one image with another. This approach allows to place any descendant of View above another one.
Upvotes: 1