views:

53

answers:

2

Hi There,

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,

A: 

Why don't you just turn black pixels into transparent pixels?

LordTwaroog
hi there, thanks for your reply, well, it'll take a very long time if i should run through each pixel and change it if it's black, eg. if i'm doing a large dimension of image - 1000px x 1000px ?
AnD
+1  A: 

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);
Cpt.Ohlund
hi there,Thanks for your reply, I'll try first and get back here with the result
AnD
hi It's work even with the large dimension ~ 2000px x 1500px, but the thing is if i do it twice, the second attempt is got an exception (may be out of synch) - i put your code inside the thread
AnD