合并 2 张图像叠加 [英] Combining 2 Images overlayed

查看:19
本文介绍了合并 2 张图像叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和安卓有关系,所以,我有 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 张图像,但它是重叠的(就像给图像加水印一样),第二张图像应该首先缩放到第一张图像(相机)的大小 - 所以它们具有相同的尺寸,然后如果第二张图像像素是黑色,不要组合它(所以黑色意味着透明色 - 在第二张图像上)

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.

谢谢各位

推荐答案

用于叠加两个位图:

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

这篇关于合并 2 张图像叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆