Android 编辑位图通道
可以使用 extractAlpha()
访问给定位图的 Alpha 通道,但我还没有找到任何方法来实际设置位图的 Alpha 通道。
如何使用 Android 将多个灰度图像作为通道重新组合成位图?
It's possible to access the alpha channel of a given bitmap with extractAlpha()
, but I haven't been able to find any way to actually set the alpha channel of a bitmap.
How can multiple greyscale images be recombined as channels into a Bitmap with Android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很有可能将单独的通道重新组合回 ARGB 图像。您只需要灰度通道图像和具有您想要的 Alpha 通道的图像 - 请注意,这不是不透明的灰度图像,而是具有您想要的 Alpha 通道的图像。然后,您可以使用适当的
PorterDuffXfermode
使用Paint
将每个通道绘制到空白的黑色填充位图上。使用上面的代码和以下 4 个图像(分别为红色、绿色、蓝色和 alpha):
我们得到以下结果:
简单说明:红色椭圆形是不透明的,透明背景上的红色椭圆形 - 颜色对此并不重要,但 alpha 却很重要
It is quite possible to re-combine separate channels back into an ARGB image. You just need the grayscale channel images and an image with the alpha channel you want - note that this is not an opaque grayscale image, but an image with the alpha you want. You then draw each channel with a
Paint
using the appropriatePorterDuffXfermode
onto a blank, black-filled Bitmap.With the above code and the following 4 images (red, green, blue, and alpha, respectively):
We get the following result:
Just a quick note: the red oval is an opaque, red oval on a transparent background - the color doesn't matter for this one, but the alpha does
当直接访问像素(字节)时,操作位图是一件非常简单的事情。
要在 Android 中执行此操作,您可以通过此方法完成。
现在您可以进行任何您喜欢的图像处理、转换或组合。
我希望这就是您正在寻找的。
Manipulating Bitmaps is a farily simple thing, when to access the pixel (bytes) directly.
To do that in Android you can do it over this approch
Now you can do any image manipulation, tranformation or combination you like.
I hope this is what you were looking for.
你尝试过用画布吗?下面看起来像是一个 hack,但也许它会起作用。我自己没有测试过。
Have you tried with canvas? The following looks like a hack, but maybe it will work. I have not tested it myself.