Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine multiple images into a single image in android?

Tags:

android

image

I am working on a distributed application of android.I have splitted a single image into lets say 4 parts and then processed it. Now I want to combine 4 bitmap images into a single image. How can i do that?

like image 795
vinesh Avatar asked Mar 01 '13 06:03

vinesh


People also ask

How do I combine multiple images into one image?

Open the Photo Gallery and locate the folder that contains photos you want to combine. Hold CTRL key to select multiple images and then click on the Photo Gallery's Create tab. Select the Photo Fuse feature and proceed to designate the area of the photo you want to replace.

How do I paste a picture into another picture on android?

Select what you want to copy. Tap Copy. Touch & hold where you want to paste. Tap Paste.

What is combining multiple images?

What is Compositing? Photo compositing is when you combine elements from multiple images, in order to create a brand new image. Compositing can be tricky to do, but it's a lot of fun!


2 Answers

Bitmap[] parts = new Bitmap[4];
Bitmap result = Bitmap.createBitmap(parts[0].getWidth() * 2, parts[0].getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < parts.length; i++) {
    canvas.drawBitmap(parts[i], parts[i].getWidth() * (i % 2), parts[i].getHeight() * (i / 2), paint);
}

Something like this =)

like image 84
Anton Avatar answered Oct 04 '22 22:10

Anton


Following piece of code will do the trick for you to combine four bitmaps in one. Call this method 3 times to combine the four images.

Step 1:Combine first two images

Step 2:Combine the renaming two images

Step 3:Combine the the two new created bitmaps

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);
        return bmOverlay;
    }
like image 33
Karan_Rana Avatar answered Oct 04 '22 23:10

Karan_Rana