J2ME Nokia UI API Quick Reference[小糊涂的灵感]

J2ME Nokia UI API Quick Reference
com.nokia.mid.ui.FullCanvas: similar to javax.microedition.lcdui.Canvas, with full screen capability, in Nokia series 60, you can use all 176x208 by this class
com.nokia.mid.ui.DirectGraphics: similar to Graphics class, with more powerful methods, like drawPolygon, e.g. (extract from Nokia UIAPI_Guide.pdf):

 int [] polygonX = { 30, 50, 30, 10 };
 int [] polygonY = { 10, 30, 50, 30} ;
 
 void paintDiamond(Graphics g)
 {
  com.nokia.mid.ui.DirectGraphics dg;

  dg = com.nokia.mid.ui.DirectUtils.getDirectGraphics(g);
  // a diamond shape will be painted on screen
  dg.drawPolygon(polygonX, 0, polygonY, 0, polygonX.length, 0);
 }


Another example, using the flip capability:
 // assume "img" is a pre-loaded image (assume u know how to load)
 // e.g. img = Image.createImage(xxxx);
 // peter: skip the long "com.nokia.mid.ui...." assume u add this
 DirectGraphics dg = DirectUtils.getDirectGraphics(g);
 // flip left to right, right to left (like mirror)
 dg.drawImage(img, x, y, anchor, DirectGraphics.FLIP_HORIZONTAL);


 // another rotation example
 DirectGraphics dg = DirectUtils.getDirectGraphics(g);
 dg.drawImage(img, x, y, anchor, DirectGraphics.ROTATE_90);
 // rotate clockwise (right turn)

 // anchor = Graphics.TOP | Graphics.LEFT

com.nokia.mid.ui.DirectUtils : create "mutable" images (mutable means changable), example here:
 // syntax: Image img = DirectUtils.createImage(100, 100, 0x0000000);
 // last parameter 0x000000 is the opacity, or transparency (alpha)

 // assume fivemen.png is an image contains 5 men, each man is 12x12
 // dimension of fivemen.png is 60x12 (width x height)
 Image fivemen = Image.createImage("/fivemen.png");
 Image man[] = new Image[5];
 for (int i=0; i<5; i++) {
  man[i] = DirectUtils.createImage(12, 12, 0x00000000);
  Graphics g = man[i].getGraphics();
  // think: why -12 * i ?? (move the cursor to left and paint!)
  g.drawImage(fivemen, -12*i, 0, Graphics.TOP | Graphics.LEFT);
 }


Create inverted image:
 Image createInvertedImage(Image img)
 {
  int width = img.getWidth();
  int height = img.getHeight();
  Image newImage = DirectUtils.createImage(width,height,0x000000);
  
  int numBytes = (width * height + 7) / 8;
  byte[] pixels = new byte[numBytes];
  byte[] transparencyMask = new byte[numBytes];
  Graphics g = img.getGraphics();
  DirectGraphics dg = DirectUtils.getDirectGraphics(g);
  dg.getPixels(pixels, transparencyMask, 0, width,
  0, 0, width, height, DirectGraphics.TYPE_BYTE_1_GRAY_VERTICAL);
  // here, we convert black to white (only b/w image)
  // some function can do ARGB
 }

more to come later ...

Never giveup. Thanks the world.
原文地址:https://www.cnblogs.com/cnsoft/p/71702.html