您可以使用Pngcrush其主要目的是通過嘗試不同的壓縮級別和寬度或長度的PNG過濾methods.If大小減少PNG IDAT數據流的規模是非常大的,你打算後繪製在畫布上,創建圖像,可以在canvas的繪製方法中使用Graphics的drawRegion方法在其上繪製所需的圖像。您可以通過更改drawRegion()方法的參數並更改drawRegion()方法的參數來更改繪製的圖像片段(例如,當用戶按下某個鍵時)重繪畫布:
public class CanvasButterfly extends Canvas implements ... {
private int ix, iy;
//image
private Image picture;
/*
* Constructor
*/
public CanvasButterfly() {
init();
}
/* Function : paint(Graphics)
* Description : This method is used for rendering Graphics
* Input : Graphics
* return : Void
*/
protected void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
if (picture != null) {
g.drawRegion(picture, ix, iy,
picture.getWidth() - ix, picture.getHeight() - iy,
Sprite.TRANS_NONE, 0, 0, Graphics.TOP | Graphics.LEFT);
}
}
/* Function : moveImage(int)
* Description : This method handle Canvas events
* Input : void
* return : Void
*/
private void moveImage(int keyCode) {
int key = -1;
try {
key = getGameAction(keyCode);
} catch (Exception ex) {
key = keyCode;
}
switch (key) {
case Canvas.DOWN:
iy = Math.min(iy + 1,picture.getHeight());
break;
case Canvas.UP:
iy = Math.max(iy - 1,0);
break;
case Canvas.LEFT:
ix = Math.max(ix - 1,0);
break;
case Canvas.RIGHT:
ix = Math.min(ix + 1,picture.getWidth());
break;
}
}
//keyPressed
public void keyPressed(int keyCode) {
moveImage(keyCode);
repaint();
}
//keyRepeated
public void keyRepeated(int keyCode) {
moveImage(keyCode);
repaint();
}
/* Function : init()
* Description : This method initialized the class objects
* Input : void
* return : Void
*/
private void init() {
//
ix = ...
iy = ...
try {
picture= Image.createImage("/" + image + ".png");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
這裏,第一次從座標(ix,iy)在畫布中繪製圖片。
檢查[圖形中的剪輯和翻譯API](http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Graphics.html#clip )。另一個值得期待的API是[TiledLayer](http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/game/TiledLayer.html) – gnat