程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> J2ME Nokia UI API Quick Reference

J2ME Nokia UI API Quick Reference

編輯:J2ME

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 ...

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved