Con*_*ver 13 android bitmap matrix
我正在开发一个Android应用程序,帮助用户通过草绘或绘图复制位图的一部分.我的意思是用户将在Canvas上绘制一些具有位图作为背景的形状,然后我将这些点着色为位图(位矩阵/ 2D位阵列).直到这里每个人都听起来不错.
现在的问题是如何复制矩阵中具有相应真位的图像部分?
1)主图像:
2)图像作为画布背景:
3)画布上的一些画作:
4)绘制区域的位矩阵表示:
5)预期产出:
你可以这样做。该示例使用一个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;
}
Run Code Online (Sandbox Code Playgroud)
例如,使用此源:
这个过滤器:
你得到这个过滤后的图像:
| 归档时间: |
|
| 查看次数: |
1133 次 |
| 最近记录: |