I’m trying to create a bitmap with a transparent background on blackberry with the following code.
Bitmap bmp2 = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR,w, h);
bmp2.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
bmp2.setARGB(new int[w*h], 0, w, 0, 0, w, h);
Graphics g3 = Graphics.create(bmp2);
int orig = g3.getGlobalAlpha();
g3.setGlobalAlpha(0);
g3.setBackgroundColor(0x00ffffff);
g3.clear();
g3.setGlobalAlpha(orig);
g3.setColor(Color.BLACK);
g3.setFont(myFont);
g3.drawText(sig.getText(),0,0);
but my image ALWAYS has a white filled background? Any pointers on what i’m doing wrong? Thanks
EDIT
I just realised that the code above works on os6+ simulators but not on OS5 simulators.. any ideas why this is happening?
After trawling around the internet for a solution I finally discovered that there’s a bug in BB OS5 SDK that removes transparency from a png image when encoding http://supportforums.blackberry.com/t5/Java-Development/Bug-in-PNG-Encoding-Bitmap-to-PNG-with-transparency/td-p/208614 , so i had to look for a png encoder that would work for me. After searching i found this one http://code.google.com/p/qrcoder/source/browse/blackberry/src/th/co/yellowpages/javame/PNGEncoder.java?r=ae0257b8aad8c231d80cf34a244e402b3fecee22 and it worked flawlessly for me. I used it like so.
I just wrote encBytes to a file and I got my flawless transparent PNG!!