tags:

views:

237

answers:

1

Can anyone tell me how i can parse a png image into many png images in J2ME???

for examole:I just wnat to have a source image 150*150 pixel and parse it to 10 image with 15*15 pixel.

I write an elemantary code that have exeption.

This is my code:

public class HelloMIDlet extends MIDlet implements CommandListener {
private boolean midletPaused = false;

private Command exitCommand;
private Form form;
private StringItem stringItem;
Image im , im2;
Form form1 = null;

public HelloMIDlet() {
    try {
        // create source image
        im = Image.createImage("/image1.JPG");

        int height = im.getHeight() ;
        int width = im.getWidth() ;
        int x = 0 ;
        int y = 0 ;

        while ( y < height ){

             while ( x < width ){

                 // create 15*15 pixel of source image
                 im2 = im.createImage(im, x, y, 15, 15, Sprite.TRANS_NONE) ;
                 x += 15 ;
             }

             y += 15 ;
             x = 0 ;
        }          
    } 
    catch (IOException ex) {
        ex.printStackTrace();
    }

}

please help me to make it right....It's emergency!

Thanks a lot guys...

A: 

Maybe if I understand it right, you have a single image 150x150 that contains many other images put into one. If that is the case, have indexes for each of the image and use Graphics.setClip() when you paint and paint the image in the appropriate coordinate. For example you want to paint the image at say 15, 15 of the image to the coordinate 50, 50 in the device screen.

...
g.setClip(15, 15);
g.drawImage(image, 35, 35, g.TOP | g.LEFT);
...

Hope that helps

Ram