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: 40
Registered: ‎04-01-2009
My Device: Torch 9810
My Carrier: Rogers
Accepted Solution

Bitmap rotation with drawTexturedPath

[ Edited ]

I am trying to find the fastest way to draw a bitmap at an arbitrary angle.  Here is what I have so far:

 

 

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.drawTexturedPath(xPts, yPts, null, null, x, y, dvx, dux, dvy, duy, bm);
}

The problem is that drawTexturedPath does exactly what it was designed for: it draws a path.  Could anyone kindly suggest a way of hiding the path part so the rotated image wouldn't have a stroke around it?  Are there other ways to draw a rotated image quicky and with a quality comparable to what drawTexturedPath produces?

 

Highlighted
Developer
Posts: 40
Registered: ‎04-01-2009
My Device: Torch 9810
My Carrier: Rogers

Re: Bitmap rotation with drawTexturedPath

[ Edited ]

I've found the source of the problem.  Apparently the path is only drawn when you enable polygon anti-aliasing by calling

graphics.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true);

Removing this line solved the problem.

Developer
Posts: 44
Registered: ‎02-21-2010
My Device: Z10
My Carrier: AT&T

Re: Bitmap rotation with drawTexturedPath

[ Edited ]

Can anyone explain how to modify this code so that the bitmap is rotated around its center instead of its corner?  I would like it to behave like this code:

 

http://rim.lithium.com/t5/Java-Development/How-to-rotate-an-image/m-p/188685

 

...but faster.

 

Thanks in advance