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

转载于:https://www.cnblogs.com/cnsoft/archive/2004/12/01/71702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值