J2ME - zoom in

hai,how can we zoom in for a paricular map in j2me? it should be like that car race front view game. help me....thanks.
[140 byte] By [urekhaa] at [2007-10-3 3:25:29]
# 1

Hi,

To zoom follow the following procedure

1) Get the RGB data of image.

2) According to zooming factors(x and y) copy the number of pixels

down and horrizontally

3) Then from this create a new image which is zoomed image

following is the code I have tried which is possible in MIDP2.0 in

MIDP1.0 you have to use another APIs to get the RGB data of Image

public static Image zoomImage(Image Img,int ZoomFactor)

{

ImgHeight=Img.getHeight();

ImgWidth=Img.getWidth();

ImgRGBdata=new int[ImgWidth*ImgHeight];

NewImgRGBdata=new int[(ImgWidth*ZoomFactor)*(ImgHeight*ZoomFactor)];

Img.getRGB(ImgRGBdata,0,ImgWidth,0,0,ImgWidth,ImgHeight);

//System.out.println("length"+ImgRGBdata.length);

//System.out.println(ImgHeight);

//System.out.println(ImgWidth);

//System.out.println(ZoomFactor);

//System.out.println(ImgRGBdata.length);

//System.out.println(NewImgRGBdata.length);

int j=0;

if(ZoomFactor<=1)

return Img;

for(int i=0;i<ImgRGBdata.length;i++)

{

for(int k=0;k<ZoomFactor;k++)

{

NewImgRGBdata[j]=ImgRGBdata[i];

j++;

}

if(j%(ImgWidth*ZoomFactor)==0)

{

for(int l=0;l<(ImgWidth*ZoomFactor);l++)

{

for(int m=0;m<(ZoomFactor-1);m++)

{

NewImgRGBdata[j]=NewImgRGBdata[j-(ImgWidth*ZoomFactor)];

j++;

}

}

}

}

//for(int i=0;i<NewImgRGBdata.length;i++)

//System.out.println(i+1+" "+NewImgRGBdata[i]);

//

ZoomedImg=Image.createRGBImage(NewImgRGBdata,(ImgWidth*ZoomFactor),(ImgHeight*ZoomFactor),true);

return ZoomedImg;

}

@rjun

>

arjunamatea at 2007-7-14 21:18:27 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
but its giving cannot resolve symbols but when I declared those variable in method runs fine-simple prince
simpleprincea at 2007-7-14 21:18:27 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
its static method so the symbolls that are getting not resolved just declare them according to thier datatypes@rjun
arjunamatea at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

Hi arjun,

I tried this code, but the control is not going further from line

Img.getRGB(ImgRGBdata,0,ImgWidth,0,0,ImgWidth,ImgHeight);

i have put this in try catch block but there is not exception also, but the control is not going after this line, as i have printed a line after this.

can give me any idea what i might be doing wrong?

Thanks in advance,

ilmiana at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

what is zoomingFactor value, Image memory size and image type. If image size is very large and you again zoom it then it can give heapsize proble or execution will hang

first just try with small images if it runs fine then there is no fault in code otherwise i will again check the code

@rjun

arjunamatea at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

The zooming factor is 2 and image size is just 900bytes and width heigth are 23*27, and its a jpg image. i think with this image size there shouldnt be any memory issue.

But i am wounder why is it not throwing any exception. :(, but the control doesnt move further from

img.getRGB(....).

so kindly see if u can help

Thanks

ilmiana at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
note that you are using jpg image, convert that image into png and then use to getRGB @rjun
arjunamatea at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
I changed the image to png and now its working fine. but can u tell me why doesnt it work for jpg?thanks alotOmar Rehman
ilmiana at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
bcoz most cell-phones does not support jpg and KVM supports png images only so there is only png decompresser is presend @rjun
arjunamatea at 2007-7-14 21:18:28 > top of Java-index,Java Mobility Forums,Java ME Technologies...