gpt4 book ai didi

android - 在ANDROID编程中从位图图像复制位矩阵

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:45:38 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序,它可以帮助用户通过素描或绘图来复制位图的一部分。我的意思是用户将在以位图为背景的 Canvas 上绘制一些形状,然后我将这些点着色为位图(位矩阵/二维位数组)。到这里为止,每个 hitng 听起来都不错。

现在的问题是如何复制矩阵中具有相应真位的图像部分?

补充说明

1) 主图:

Image be fore any process

2) 图像作为 Canvas 背景:

Image as canvas background

3) Canvas 上的一些画作:

User paints on canvas

4)绘制区域的位矩阵表示:

Bit matrix

5) 预期输出:

Where is painted is outputted

最佳答案

你可以这样做。该示例使用一个 Bitmap 作为源,另一个 Bitmap 作为过滤矩阵。过滤器位图具有透明背景,过滤后的位图也是如此:

public Bitmap doFilter(Bitmap source, Bitmap filter) {
Bitmap filtered = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());

Paint paint = new Paint();
Canvas canvas = new Canvas(filtered);

canvas.drawBitmap(source, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(filter, 0, 0, paint);

return filtered;
}

例如,使用此来源:

enter image description here

这个过滤器:

enter image description here

你得到这个过滤后的图像:

enter image description here

关于android - 在ANDROID编程中从位图图像复制位矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38181230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com