Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining 2 Images overlayed

I've got a things to do with android, so, I have 2 images, 1. image from camera 2. another image from somewhere

so what I want to achieve is how to combine those image into 1 image, but it's overlapping (just like watermarking the image), the 2nd image should be scaled first into the size of the 1st image(camera) - so they have same dimension, then if the 2nd image pixel is black, don't combine it (so the black means transparent color - on 2nd image)

do you know what is the best way achieve this, can I do this with xor or bitwise?

Any reference or sample code would be really really much appreciate.

Thanks guys,

like image 313
AnD Avatar asked Sep 09 '10 07:09

AnD


1 Answers

For overlaying two 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;
    }

And for scaling one first you should check out createScaledBitmap, e.g:

Bitmap scaledBitmap = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);
like image 190
Cpt.Ohlund Avatar answered Nov 18 '22 01:11

Cpt.Ohlund