I’m creating a nine-patch image for a widget background and I’d like to have only an area of the image partially transparent.. Is it possible to create such a PNG or to use a sort of transparency map in android? The setImageAlpha sets the transparency for the whole PNG..
Share
Yes, without any problem. PNG can feature so called alpha channel which is other word is transparency. It’s separate layer with the dimensions of the image it belongs to and each pixel of alpha channel defines transparency of corresponding pixel of image.
In PNG alpha is one byte value (from 0 (fully transparent) to 255 (opaque)), of course, is set for each pixel separately. To use transparency, your image should be RGB (true color, or in fact ARGB, where ‘A’ stands for alpha channel) PNG file and any sane graphics application should support it.
PNG also supports transparency with indexed (color mapped) images, but it works differently – in that case you choose single color in image color palette and if pixel is in that color, then it is fully transparent, otherwise it got its color from palete. Therefore you got less control on transparency as it is 0-1 type – either color is transparent or it is not. There’s no gradation.
I recommend using any graphics program like Gimp or Photoshop and play with this.