I have two images and i want to save one bitmap image over another exactly at the same point where it is present i also move image using gesture .
public Bitmap combineImages(Bitmap ScaledBitmap, Bitmap bit) { int X = bit.getWidth(); int Y = bit.getHeight(); Scaled_X = ScaledBitmap.getWidth(); scaled_Y = ScaledBitmap.getHeight(); System.out.println("Combined Images"); System.out.println("Bit :" + X + "/t" + Y); System.out.println("SCaled_Bitmap :" + Scaled_X + "\t" + scaled_Y); overlaybitmap = Bitmap.createBitmap(ScaledBitmap.getWidth(), ScaledBitmap.getHeight(), ScaledBitmap.getConfig()); Canvas canvas = new Canvas(overlaybitmap); canvas.drawBitmap(ScaledBitmap, new Matrix(), null); canvas.drawBitmap(bit, new Matrix(), null); return overlaybitmap; }
Any help would be greatly appreciated.
you can combine two bitmaps like this
public static 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, 0, 0, null); bmp1.recycle(); bmp2.recycle(); return bmOverlay; }
you can combine two bitmaps i.e a bitmap on another bitmap as an overlay
try this below code:
public Bitmap bitmapOverlayToCenter(Bitmap bitmap1, Bitmap overlayBitmap) { int bitmap1Width = bitmap1.getWidth(); int bitmap1Height = bitmap1.getHeight(); int bitmap2Width = overlayBitmap.getWidth(); int bitmap2Height = overlayBitmap.getHeight(); float marginLeft = (float) (bitmap1Width * 0.5 - bitmap2Width * 0.5); float marginTop = (float) (bitmap1Height * 0.5 - bitmap2Height * 0.5); Bitmap finalBitmap = Bitmap.createBitmap(bitmap1Width, bitmap1Height, bitmap1.getConfig()); Canvas canvas = new Canvas(finalBitmap); canvas.drawBitmap(bitmap1, new Matrix(), null); canvas.drawBitmap(overlayBitmap, marginLeft, marginTop, null); return finalBitmap; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With