Warlock
Warlock

Reputation: 45

Merge two bitmaps(png) with code

In my android app. I want to merge two images to produce one so i can use.

this is what i have

\n

I have This image

i want to merge it with another image in each place So the result will be like this Any help will be appreciated 😊

Upvotes: 0

Views: 50

Answers (1)

Jay
Jay

Reputation: 324

This sounds similar to what you are looking for.

Basically you need to create a Bitmap, create a Canvas, then draw each image on the canvas. I'm not positive how they will work as being PNG's and being able to see both images, but this is how I've drawn multiple images into one. I would guess that you draw each image starting at the same position (unlike the way I did it).

Hope this helps.

result = Bitmap.createBitmap((bmImages[0].getWidth() * 2) + 45, (bmImages[0].getHeight()) + 30, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(result);
for (int i = 0; i < bmImages.length; i++) {
    canvas.drawBitmap(bmImages[i], (bmImages[i].getWidth() * (i % 2)) + ((i+1)*15), 15, null);
    bmImages[i].recycle();
}

Upvotes: 1

Related Questions