During Game Development, we often need to synthesize a relatively large image from fragmented small images. When we need to use these images, we can use setClip to draw a small part of this big image, you can also use setClip to split a large image into a small image and then call the small image directly.
The following example shows how to split an image.
Create an Image array: Image [] imgNumbers = new Image [10];
Private void initImgNumbers () throws Exception {
Image imgTotal = Image. createImage (...);
Graphics g;
For (int I = 0; I <10; I ++ ){
ImgNumbers [I] = Image. createImage (10, 15); // initialize the Image array. The size is 10X15.
G = imgNumbers [I]. getGraphics ();
G. drawImage (imgTotal,-I * 10, 0, 20 );
}
}
It should be noted that the above method in MIDP 1.0 will lose the transparent pixels in the image. There are two remedial measures:
First, use setClip to draw a big image;
Second, use the following code for Nokia's camera:
ImgNumbers [I] = DirectUtils. createImage (10, 15, 0 );
You can.