Use Nokia ui api to rotate images in j2s

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.