You can use Pngcrush Its main purpose is to reduce the size of the PNG IDAT datastream by trying various compression levels and PNG filter methods.If size of width or length is very large and you intend draw it on canvas,after creating image,you can use drawRegion method of Graphics in paint method of canvas to draw desired piece of image on it.You can change drawed piece of image(for example when user press a key)by change parameters of drawRegion() method and repaint canvas:
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();
}
}
}
Here,first time picture drawn from Coordinate(ix,iy) in canvas.