分类: 嵌入式
2011-08-17 16:00:48
实现透明度渐变有两种方法,一是使用蒙板;二是直接修改像素数据,修改每个 像素的 alpha 值。
对于蒙板法,事先做好一张透明度渐变的图,这就是我们的蒙板,在绘制完图像 之后把蒙板图片绘制上去,这样就产生了透明度渐变的效果。
对于第二种方法,我们需要首先读出图片的数据,然后修改每个像素的 alpha 值。下面的代码片段的功能是逐行增加 alpha 值,产生的效果是自上向下由暗 变亮。
int alpha = 0x00000000;
Returns in pixels[] a copy of the data in the bitmap. Each value is a packed int representing a . The stride parameter allows the caller to allow for gaps in the returned pixels array between rows. For normal packed results, just pass width for the stride value.
The Color class defines methods for creating and converting color ints. Colors are represented as packed ints, made up of 4 bytes: alpha, red, green, blue. The values are unpremultiplied, meaning any transparency is stored solely in the alpha component, and not in the color components. The components are stored as follows (alpha << 24) | (red << 16) | (green << 8) | blue. Each component ranges between 0..255 with 0 meaning no contribution for that component, and 255 meaning 100% contribution. Thus opaque-black would be 0xFF000000 (100% opaque but no contributes from red, gree, blue, and opaque-white would be 0xFFFFFFFF