Use Nokia ui api to rotate images in j2s
Author: Chen yuefeng
From: http: // blog/csdn.net/mailbomb
In midp1.0, the image rotation method is not provided. In the sprite class of midp2.0, the image rotation method is provided.
Nokia's ui api directly provides a method to rotate the original image when drawing the image. This method is useful when users need to display different content in four directions to draw shells in the game, which can save the space occupied by the program.
This function is implemented by the drawimage method in the directgraphics interface. To use this function, you must first introduce the com. Nokia. Mid. UI package. The declaration of this method is as follows:
Public void drawimage (image IMG, int X, int y, int anchor, int manipulation)
The parameters are used as follows:
IMG -- image object to be drawn
X -- X coordinate in the upper left corner of the image
Y -- y coordinate in the upper left corner of the image
Anchor -- How to Use coordinates
Manipulation -- Rotation Angle
The first four parameters are exactly the same as the drawimage method in graphics. The fifth parameter can be selected as follows:
Rotate_90 -- Rotate 90 degrees
Rotate_180 -- rotate 180 degrees
Rotate_270 -- rotate 270 degrees
Note: All rotations are counter-clockwise.
Actual code:
// Create a directgraphics-type object from the system's graphics object
Directgraphics DG = directutils. getdirectgraphics (g );
// Draw an image with a rotation of 90
DG. drawimage (IMG, 30, 30, graphics. Top | graphics. Left, directgraphics. rotate_90 );
The code above shows the image represented by IMG, which is drawn after 90 degrees of rotation counterclockwise.