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
>
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,
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
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