- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想改变图像特定部分的亮度。我知道如何使用 ColorMatrix 更改图像的亮度(或色调)。但它将应用于整个图像。
我有一个 mask 文件(黑白图像)。我想仅在该 mask 的白色部分应用亮度变化。如何在 Android 中执行此操作?
下面是蒙版图片和我想要得到的结果。
最佳答案
对于给定的位图和 mask :
首先创建一个临时位图:
bitmap = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.bitmap);
mask = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.mask);
float[] src = {
0, 0, 0, 0, 255,
0, 0, 0, 0, 255,
0, 0, 0, 0, 255,
1, 1, 1, -1, 0,
};
ColorMatrix cm = new ColorMatrix(src);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm);
maskPaint = new Paint();
maskPaint.setColorFilter(filter);
maskPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
filteredBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(filteredBitmap);
c.drawBitmap(bitmap, 0, 0, null);
c.drawBitmap(mask, 0, 0, maskPaint);
colorFilterPaint = new Paint();
colorFilterPaint.setColorFilter(new LightingColorFilter(0xffffff, 0x880000));
并绘制它(我把它放大了,因为我的模拟器缩小了它):
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.scale(3, 3);
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.drawBitmap(filteredBitmap, 0, 0, colorFilterPaint);
canvas.restore();
}
结果是:
关于Android 在带有 mask 的部分 imageView 上应用 colorMatrix colorFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16140501/
我正在更改 ImageView 的亮度、对比度、饱和度和色调。我在上面搜索了很多。 我得到了一些适用于 ColorMatrix 的代码。 [1.] 对于亮度 ColorMatrix 是类似的东西
我正在使用以下代码使我的图片变黑 BitmapDrawable bdarw = new BitmapDrawable(imagePath); ColorMatrix c
作为学校项目的一部分,我正在尝试运行 MSDN 文章中的一些稍微修改过的代码。目标是使用颜色矩阵为图片框中的位图重新着色。这是我的代码: float[][] colorMatrixEl
我正在根据计算更改图像中每个像素的颜色值。问题是这在我的机器上使用 1000x1333 图像需要超过 5 秒,我正在寻找一种方法来优化它以使其更快。 我想 ColorMatrix可能是一种选择,但我很
我想尝试使用 ColorMatrix ,但我只能找到将图像转换为灰度的示例。即便如此,它们往往会被呈现为一大块“魔数(Magic Number)”代码,没有任何解释。 有人知道如何使用 ColorMa
我正在尝试使用 ColorMatrix 调整图像的亮度(您可以在 Photoshop 中尝试调整色相时看到此选项,亮度和亮度也是两个不同的功能)使用 ColorMatrix 但不知道要更改哪些值才能实
在开始之前,我使用的是 C#。我想使用 ColorMatrix 类进行一些转换。问题是有时 r、g 或 b 会发生溢出。矩阵没有将值固定在 255,而是循环并再次从 0 开始。这意味着,对于应该显示为
我已阅读 ColorMatrix文档,它说了以下内容: 5x4 matrix for transforming the color+alpha components of a Bitmap. The
我正在做一些图像处理应用程序的工作(为了好玩),并且正在努力完全理解 ColorMatrix 转换的工作原理。我掌握了线性/仿射变换的基础知识,并且可以通过在线复制示例很好地掌握,但我想完全掌握某些东
在 XNA 中,如何实现与应用 System.Drawing.Imaging.ColorMatrix 相同的效果?下面的文章展示了我想如何渲染我的 Sprite ,但它使用了 GDI+: http:/
我的工具栏上有一个圆形的 ProgressBar 来显示一些不确定的进度,但是 ProgressBar 的默认样式(我知道的唯一一个使它变成圆环的样式)与工具栏的颜色相同('colorPrimary
我有一张图片,如果像素 (x,y).R < 165,我想将像素设置为白色。 之后我想将所有非白色的像素设置为黑色。 我可以使用 ColorMatrix 做到这一点吗? 最佳答案 你不能用颜色矩阵来做到
我需要创建一个自定义 CSS 过滤器,将黑白图像转换为具有两种自定义颜色的双色图像。 我想以这种方式应用过滤器(不确定这种语法是否可行,可能必须单独传递 6 个参数): .duotone {
我正在尝试在 Swift 中重新编写我的 Android 应用程序以启动 iOS,但我已经遇到了障碍...... Android 应用程序是关于基于 ColorMatrix 总和的图像处理......
我正在尝试使用 ColorMatrix 为整个图像设置一个恒定的色调值。我的目标是使整个图像看起来颜色相同,而不会失去任何区域的亮度。我找到了一种使用 ColorMatrix 来移动图像的色调值的方法
我正在 Canvas 上工作,并使用 EaselJS 库来玩。使用 EaselJS,我可以使用过滤器应用 ColorMatrix const myGraphics = new createjs
查看 Android 文档,ColorMatrix setSaturation() method说: Set the matrix to affect the saturation of colors
为了回答这个问题,我将粘贴 Vibrance 的定义以及它与常规 Saturation 的不同之处。 Vibrance is a smart-tool which cleverly increases
我有 2 个表单,A 和 B。在表单 A 上,我单击一个按钮,图像被加载到位于表单 B 上的 PictureBox 中。并且,我想通过以下方式将 GrayScale 设置为此图像: public
我想改变图像特定部分的亮度。我知道如何使用 ColorMatrix 更改图像的亮度(或色调)。但它将应用于整个图像。 我有一个 mask 文件(黑白图像)。我想仅在该 mask 的白色部分应用亮度变化
我是一名优秀的程序员,十分优秀!