Image img, errImg, outImg;
boolean error;

public ZoomCanvas(Display display) {
try {
errImg = Image.createImage("/error.png");
img = Image.createImage("/2-2.png");
} catch(Exception e) {
Alert alert = new Alert("ERROR", "No Image Available", errImg, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
error = true;
}
}

public void paint(Graphics g) {
if(!error) {
g.setGrayScale(255);
g.fillRect(0, 0, getWidth(), getHeight());
}

if(outImg != null) {
g.drawImage(outImg, getWidth()/2, getHeight()/2, g.HCENTER | g.VCENTER);
} else {
g.drawImage(img, getWidth()/2, getHeight()/2, g.HCENTER | g.VCENTER);
}
}

public void zoomIn(Display display) {

outImg = null;
int[] rgbOutput = null;

Graphics g = null;
int width = 0, height = 0;

try {

width = img.getWidth();
height = img.getHeight();

outImg = Image.createImage(width<<1,height<<1);

int rgbInput[]=new int[width*height];
rgbOutput = new int[(width<<1)*(height<<1)];

img.getRGB(rgbInput,0,width,0,0,width,height);

int i,j,k;
k=0;
for(i=0;i<(height<<1);i+=2) {
for(j=0;j<(width<<1);j+=2) {
rgbOutput[i*(width<<1) + j] = rgbInput[k] ;
rgbOutput[(i+1)*(width<<1) + j] = rgbInput[k];
rgbOutput[i*(width<<1) + j+1] = rgbInput[k];
rgbOutput[(i+1)*(width<<1) + j+1] = rgbInput[k];
k++;
}
}
g = outImg.getGraphics();
} catch(Exception e){
System.out.println("ZoomImage Error" + e.getMessage());
e.printStackTrace();
}

outImg = outImg.createRGBImage(rgbOutput,width<<1,height<<1,true);


}

public void zoomImage(Display display) {

outImg = null;

int[] rgbOutput = null;
Graphics g = null;
int width = 0, height = 0;

try {

width = img.getWidth();
height = img.getHeight();
System.out.println(width);
System.out.println(height);
outImg = Image.createImage(width, height);
int rgbInput[] = new int[width * height];

rgbOutput = new int[width * height];
img.getRGB(rgbInput, 0, width, 0, 0, width, height);

int i,j,k,l;
k=0;
int tempArr[][] = new int[height][width];

for(i=0;i<height;i++)
for(j=0;j<width;j++)
tempArr[i][j] = rgbInput[k++];
k=0;
for(i=0;i<height;i++) {
for(j=0;j<width;j++) {
rgbOutput[k]= tempArr[j][i];
k++;
System.out.println("i, j, k : " + i + "," + j + "," + k);
}
}

g = outImg.getGraphics();

} catch(Exception e){
System.out.println("ZoomImage Error" + e.getMessage());
e.printStackTrace();
}

outImg = outImg.createRGBImage(rgbOutput,height,width,true);
}



}




i am working on the image zoom in and zoom out effect, but it doesn't work properly. Please guide me so that this code wil work properly.

every reply will be appritiated.

Thanx and regards,

Ashish