结合2图像重叠图像

2023-09-04 08:52:14 作者:颜面

我还有事情要做与Android, 所以,我有2个图像, 从相机1.图像 2.从某处另一个图像

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

所以我想实现的是如何将这些图像组合为1的图像,但它的重叠(就像水印的图像), 第二图像应首先换算成第一图像(摄像头)的大小 - 所以他们有相同的尺寸,那么如果第二图像像素是黑色的,不结合起来(因此黑色意味着透明的颜色 - 2日图片)

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?

任何参考或样品code是真的真的很多AP preciate。

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

谢谢你们,

推荐答案

有关叠加两个位图:

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;
    }

和缩放一个第一,你应该看看createScaledBitmap,例如:

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

Bitmap scaledBitmap = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);