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 (){