04-13-2009 12:46 PM
If you mean the second line, yes I did.
Bitmap source = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR, width, height);
int  data = new int[width * height];
for(int i=0; i<data.length;i++)
data[i] = 0x10000020;
source.setARGB(data, 0, width, 0, 0, width, height);
PNGEncodedImage png = PNGEncodedImage.encode(source);
png.hasAlpha(); //RETURNS FALSE
png.hasTransparency(); //RETURNS FALSE
int data_read_back = new int[width * height];
04-13-2009 12:58 PM
Do not create your bitmap with 16-bit pixel depth. You don't need to put that flag in there. Do it the way I said????
Did you try it exactly the same as below????
Bitmap source = new Bitmap(width, height); int  data = new int[width * height]; for(int i=0; i<data.length;i++) data[i] = 0x10000020; source.setARGB(data, 0, width, 0, 0, width, height);
That should work!!!
With your new Bitmap statement, you are stating that you want your bitmap to be a 565 or some format like that.
By default it'll choose ARGB or at the very least RGB. You might beed the createAlpha call, but I'd try it without it first.
04-13-2009 02:17 PM
I've finally taken a closer look at your problem.
What I've noticed is that Bitmaps ARE created as 16 bpp internally. You can set the color from a 32-bit ARGB value, and it'll get converted into 565 mode for the RGB part and 8-bit for the alpha part if you've called createAlpha appropriately.
However, I couldn't get the alpha to show with a bitmap. You kind of have to render the bitmap over a button or something, which is hard using the layout managers as they stop fields from overlapping one another. Also getting to see through your screen is tough as by default there is a hard coded background to any screen so seeing through your background color will show through to white. The exception is a POP-UP screen. I have gotten 24-bt alpha values to work with pop-up screens. Now I haven't tried this with Bitmaps though, just with the background color of a popup yes/no type dialog.
So, if I were really interested in working with alpha values, I'd probably use an encoded image and use Graphics.drawImage to draw it into the screen. You should be able to do it with the Bitmap, but you won't have 32-bit color internally if you do it that way.
PNG is usually the best image format to use for drawing alpha.....I've found.
Post what you find out here. I'd be really interested to see what you discover.
04-13-2009 02:24 PM
04-13-2009 02:52 PM - edited 04-13-2009 02:53 PM
Thanks for your answer. My earlier attempts to do drawImage with a png with alpha values in it were successful. So I know that the transparency works with a png.
Also, drawBitmap with a bitmap with alpha values works
My question is it does not work when you try to create a png from a bitmap with transparency values.
Interestingly, when you decompress a png and get its bitmap, you would see alpha values correctly. However, when you try to create a png image back from this bitmap, the alpha values will be lost.
The question is not whether I need this or not but whether this is a bug or not. Because PNGEncodedImage.encode function does not do what it is supposed to do which is successfully encoding a bitmap with alpha values into a png with alpha values.
04-23-2009 09:17 AM
01-14-2012 01:26 PM
shism, use this class by Patchou... it's very easy and works with transparent pngs