如何Alpha遮罩颜色 [英] How to alpha mask a color

查看:298
本文介绍了如何Alpha遮罩颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工作中的Andr​​oid(1.5),我有一百个左右的灰度图像的字节数组的形式。我想使用的图像作为阿尔法口罩在Canvas绘图纯色。图像是固定的,但是颜色可以改变。我可以为每个图像/颜色组合位图对象,但是这似乎是非常低效的。什么是处理这个问题,在内存和速度方面的好办法? (我需要做很多次的每个图像/颜色组合。)

Working in Android (1.5), I have a hundred or so grayscale images in the form of byte arrays. I want to use the images as alpha masks for drawing solid colors in a Canvas. The images are fixed but the colors can change. I can create Bitmap objects for each image/color combination, but that seems terribly inefficient. What would be a good way to approach this problem, in terms of both memory and speed? (I need to do this many times for each image/color combo.)

推荐答案

我想我找到了我一直在寻找的答案:

I think I found the answer I was looking for:

  1. 创建一个ARGB_8888位图,其中每个像素的颜色设定为(灰色&其中;&所述; 24)| 0XFFFFFF。
  2. 对于每种颜色,创建一个新的PorterDuffColorFilter(颜色,PorterDuff.Mode.MULTIPLY)。
  3. 要呈现,创建一个Paint对象并调用setColorFilter()与对应于彩色滤波器被使用。然后,使用canvas.drawBitmap的位图和画图对象调用。

对于一个单一的颜色,这可能不是一样快,建设正是我想要的位图,没有一个画图对象绘制,但它更节省空间比位图的每个图像/颜色组合。

For a single color, this probably isn't as fast as building exactly the Bitmap I want and drawing without a Paint object, but it's much more space efficient than a Bitmap for each image/color combo.

这篇关于如何Alpha遮罩颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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