/ * * CREATED ON 2004-12-4 * * Abstract: This is an example of displaying image rotation algorithms. It is an automated object, and the rotating image is then displayed. * Users only need to put originImage = image.createImage ("/ resource / popo.png"); the image file in this line is changed to * the real-existing image file can run.
* / Package SayWord; import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui *;. Import javax.microedition.midlet.MIDletStateChangeException; / ** * @author Just let me sleep wzhh@ustc.edu * * This is a MIDlet subclass * / public class hello extends MIDlet {/ ** * * / private display display; private view.getdisplay (); canvas = new ViewCanvas (this);} protected void startApp () throws MIDletStateChangeException {display.setCurrent (canvas); // set the display canvas object} protected void pauseApp () {} protected void destroyApp (boolean arg0) throws MIDletStateChangeException {} public void exitMIDlet () {try {destroyApp (true);} catch (MIDletStateChangeException e) {} notifyDestroyed ();}} // automation objects, but also the subclass Canvas class ViewCanvas extends Canvas implements CommandListener, Runnable {private Command cmExit; // EXIT MIDLET Private String Keytext = "0"; // Key Code text, used to record the user's keystroke, do not use private int Angle = 0 in this example; // Rotate angle private image originImage; // Original image private hello midlet; private boolean alive = true; private int interval = 100; private thread thread = null; / * ------------- ------------------------------------- * Constructor * ---------- ------------------------------------- * / public viewcanvas (hello midlet) {this. MIDlet = MIDLET; try {OriginImage = image.createImage ("/ resource / popo.png");} catch (exception e) {system.out.println ("Load Image fail !!!!!);} // Create EXIT Command and Listen for Events CMEXIT = New Command ("Exit"
, Command.exit, 1); Addcommand (cmexit); setcommandlistener (this); thread = new thread (this); thread.start ();} // This is a program code that rotates an angle around the center point / / ORIGINIMAGE is incorporated into the original image, the return value of the function is the rotating image // This code can only rotate the integer multiple of 30 degrees, and if you want to rotate more fine // change tabcos, tabsin, these two arrays Saved is the value of COS and SIN multiplying 4096 // Since J2ME does not support a point operation and a triangular function, SiN, cos int [] tabcos = {4096, 3547, 2048, 0, -2048 , -3547, -4096, -3547, -2048, 0, 2048, 3547}; int [] tabsin = {0, 2048, 3547, 4096, 3547, 2048, 0, -2048, -3547, -4096, - 3547, -2048}; private Image TransferImage (Image OriginImage, int angle) {int w = OriginImage.getWidth (); int h = OriginImage.getHeight (); int ARGBData [] = new int [w * h]; int TranARGBData [] = New int [w * h]; OriginImage.GetrGB (ArgbData, 0, W, 0, 0, W, H); int centerx = W / 2; int centery = h / 2; int i = ((360 - ANGLE)% 360) / 30; for (int y1 = 0; Y1