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
New Developer
TungstenX
Posts: 19
Registered: ‎03-06-2009
My Device: Bold

Using ImageManipulator to rotate a transparent bmp but getting white background

[ Edited ]

Hi All,

 

I've read the article: http://supportforums.blackberry.com/t5/Java-Development/Rotate-and-scale-bitmaps/ta-p/492524

I've also search this forum and googled a lot but I can't seem to find the answer to the following:

 

I have a bitmap image that has a transparent background.  When I rotate the image, using ImageManipulator, the transparent background from the original image is changed to white.

 

The code I use is very simple:

Bitmap bmp = ImageManipulator.rotate(ADIAL_IMAGE, angle);
g.drawBitmap(_x, _y, bmp.getWidth(), bmp.getHeight(), bmp, 0, 0);

 

Is there a way to rotate the image and keep the orginal transparent background?



There is no sex in your violence
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
My Carrier: o2

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Hi,

 

Did you find a solution to this issue, am facing the same problem.

 

BR

Suppi

BR,
Supriya
Please use plain text.
New Developer
TungstenX
Posts: 19
Registered: ‎03-06-2009
My Device: Bold

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

I couldn't find a solution. I ended up making a large mapped bitmap, manually rotating the dial hand :smileysad:


There is no sex in your violence
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
My Carrier: o2

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Well i think it is possible if the color is updated in paintTransformedBitmap in ImageManipulator class. It is set to White. That is why we get a white background. If we set this to transparent it should work. Question is how to set it to transparent?? is there is a hex code for Transparent??

BR,
Supriya
Please use plain text.
Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Hi Supriya,

 

I can suggest you one thing,

 

You can find the solution for resizing transparent images here:

http://www.patchou.com/2010/10/resizing-transparent-bitmaps-with-the-blackberry-jde/

 

Now what my suggestion is you can club this code (that helps to gaining transparency) with rotate image code.

 

Give it a try, may be you can do that.

 

Thanks.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Hex code for transparent is 0x00xxxxxx.  For completely opaque ii is 0xFFxxxxxx;

 

Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
My Carrier: o2

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Hi,

 

Thanks alot for this.

 

But if i add 0x00xxxxxx to my code its gives a syntax error, is there something else i shld add or another way of handling it.

BR,
Supriya
Please use plain text.
New Developer
TungstenX
Posts: 19
Registered: ‎03-06-2009
My Device: Bold

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

I think you should change the xxxxxx to actual rgb values thus have somethinf like 0xFF000000. I'm not sure what the rgb value should be, maybe the colour that you want transparent?


There is no sex in your violence
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
My Carrier: o2

Re: Using ImageManipulator to rotate a transparent bmp but getting white background

Ah i am so stupid...should have realized that.

 

Anyways, but then if i add rgb values then i will get an image with some background color. I want a completely transparent color.

 

I used the below code, but its slow, is there a faster process:

 

    private void drawRotatedBitmap(Graphics graphics, Bitmap bm, int angle, int x, int y) {
          int w = bm.getWidth(); int h = bm.getHeight();
          double a = Math.toRadians(angle);
          int x1 = (int) (x - h * Math.sin(a));
          int y1 = (int) (y + h * Math.cos(a));
          int x2 = (int) (x1 + w * Math.cos(a));
          int y2 = (int) (y1 + w * Math.sin(a));
          int x3 = (int) (x + w * Math.cos(a));
          int y3 = (int) (y + w * Math.sin(a));
          int xPts[] = {x, x1, x2, x3};
          int yPts[] = {y, y1, y2, y3};
          int fAngle = Fixed32.toFP(angle);
          int dvx = Fixed32.cosd(fAngle);
          int dux = -Fixed32.sind(fAngle);
          int dvy = Fixed32.sind(fAngle);         
          int duy = Fixed32.cosd(fAngle);
          graphics.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true);
          graphics.drawTexturedPath(xPts, yPts, null, null, x, y, dvx, dux, dvy, duy, bm);
        }

BR,
Supriya
Please use plain text.