Study Notes on j2-based learning platform (9)

Source: Internet
Author: User

9
MIDP low-level graphics processing

The image processing methods provided by MIDP are in javax. microedition. lcdui. It mainly includes the following classes: Display, Graphic
S, Canvas, Font, and Image.
1. Display:
Each MIDlet is composed of a Display that uses Singleton
The classes encapsulated by Pattern must be obtained using getDisplay. When the setCurrent () method is used
The subclass of playable can be used as a parameter to display related images on the screen. You can also use getCurrent () to obtain the currently active
Displayable object. At the same time, in order to obtain the screen-related attributes, you can use isColor () to return whether the screen is color, numColors (
Returns the number of colors supported by the screen. If the returned value is 2, it is black and white. Whenever the setCurrent method of Display gets the Canvas sub-
When the class is used as a parameter, the MIDP system will execute the paint method and treat the Graphics object as a parameter. Note that
The screen size of the handheld device is not fixed, so we need to use getWidth (), getHe
The ight () method is used to obtain the screen length and width.
2. Image:
The Image class is used when processing images. Based on the Generation Method of the Image class, it can be divided into two aspects: changeable and unchangeable.
You can use the isMutable method to determine whether the Image class can be modified. You can also use the getWidth () and getHeight () methods to obtain Imag.
The length and width of the e object.
You can create an unmodifiable image object by reading image files, downloading images online, and using resource bundle. Once
The image object cannot be modified, so the content of this image cannot be changed again.
Package com. graph;
/**
* @ Author You Li
*
* CopyRight (C) 2005 */
Import javax. microedition. midlet .*;
Import javax. microedition. lcdui .*;
Public class ImageEx extends MIDlet implements CommandListener {
Private Command cmdExit;
Private ImageCanvas canvas;
Public ImageEx (){
CmdExit = new Command ("Exit", Command. SCREEN, 2 );
Canvas = new ImageCanvas ();
// TODO automatically generates the constructor stub
}
Protected void startApp () throws MIDletStateChangeException {
// TODO automatically generates method stubs
Canvas. addCommand (cmdExit );
Canvas. setCommandListener (this );
Display. getDisplay (this). setCurrent (canvas );
}
Protected void pauseApp (){

Related Article

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.