10-22-2009 09:09 PM - edited 10-23-2009 11:10 AM
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?
Solved! Go to Solution.
10-23-2009 03:48 PM - edited 10-23-2009 03:49 PM
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_AAPOLY
Removing this line solved the problem.
02-26-2010 10:35 PM - edited 02-27-2010 09:32 PM
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-
...but faster.
Thanks in advance