Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon
Accepted Solution

Transparent background for Bitmap

I am trying to create a Bitmap that has a transparent Background. My current code is:

 

arrowL = new Bitmap(dem.width, dem.height); arrowL.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP); Graphics g = Graphics.create(arrowL); //Transparent background drawing g.setGlobalAlpha(0); g.setColor(0); g.fillRect(0, 0, dem.width, dem.height); g.setGlobalAlpha(255); //END TRANS //drawing code

 

 

This is not working as expected. Is there any way to make the background transparent?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Transparent background for Bitmap

[ Edited ]
Hi,

 

Try with this.

 

int width = dem.width; int height = dem.height; int dataTransparent[] = new int[width * height]; Bitmap arrowL = new Bitmap(width, height); arrowL.setARGB(dataTransparent, 0, width, 0, 0, width, height);

 

Regards

Bikas 

Message Edited by bikas on 05-14-2009 04:15 PM
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transparent background for Bitmap

That worked in terms of making the image transparent but when I go to do the drawing with a Graphics object, nothing shows up.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Transparent background for Bitmap

It should work.

 

Can you explain exactly what you want.

 

and also paste the code you are trying.

 

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transparent background for Bitmap

Oops. I double-checked my code and realized that I was setting the wrong bitmap (I have this process running twice) . I changed that and the operation worked.

 

int[] y1 = new int[] { 2, 8, 14 }; int[] y2 = new int[] { 6, 8, 10 }; int[] col1 = new int [] { 0x394C76, 0x487C98, 0x46AAAD }; int[] col2 = new int [] { 0xC94242, 0xBC7645, 0xBE8D40 }; byte[] pathType = new byte[] { Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_END_POINT, Graphics.CURVEDPATH_END_POINT }; XYDimension dem = new XYDimension(16, 16); int[] alphaC = new int[dem.width * dem.height]; arrowL = new Bitmap(dem.width, dem.height); arrowL.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP); arrowL.setARGB(alphaC, 0, dem.width, 0, 0, dem.width, dem.height); Graphics g = Graphics.create(arrowL); g.setGlobalAlpha(255); g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true); g.drawShadedFilledPath(new int[] { 3, 14, 3 }, y1, pathType, col1, null); g.drawShadedFilledPath(new int[] { 6, 9, 6 }, y2, pathType, col2, null); arrowR = new Bitmap(dem.width, dem.height); arrowR.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP); arrowR.setARGB(alphaC, 0, dem.width, 0, 0, dem.width, dem.height); //by accedent I had this set to arrowL instead of arrowR g = Graphics.create(arrowR); g.setGlobalAlpha(255); g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true); g.drawShadedFilledPath(new int[] { 14, 3, 14 }, y1, pathType, col1, null); g.drawShadedFilledPath(new int[] { 9, 6, 9 }, y2, pathType, col2, null);

 

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Developer
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630
My Carrier: verizon

Re: Transparent background for Bitmap

When i ues bikas's technique I can't seem to modify ythe pixels. They are always transparent.

Is it possible to change so that I can set the bitmap transparent & then add text for example?

thanks