×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    India
    Posts
    37

    Image Zoom in and Zoom out

    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

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: Image Zoom in and Zoom out

    Hi ashish,

    It looks that u r using the zooom out/in code specified in the following link.

    http://www.java-tips.org/java-me-tip...-zoom-out.html

    But there are lot of changes between the two.
    For eg; Image parameter is passed to both the methods. Where as in ur code Display is passed as parameter.
    Can u please post the full midlet code. so that we can test it.

    Which is the phone ur r testing. This code doesn't work on a MIDP1.0 phone..


    Wang

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    India
    Posts
    37

    Re: Image Zoom in and Zoom out

    Hello,

    Thanks for your reply. The code for ZoomIn method as found in the link - http://www.java-tips.org/java-me-ti...d-zoom-out.html did not work on Nokia 6230i. In the emulator it was giving an ArrayOutOfBounds exception.

    Please advise.

    Ashish.

  4. #4
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: Image Zoom in and Zoom out

    Hi ashish,

    What is the size of the image(resolution) ur using to zoom in & zoom out.

    You may also try the scaling of an image which will work as zoom in & zoom out.The scaling logarithm is as given below
    http://developer.sonyericsson.com/th...D=77127&#77127


    Wang

  5. #5
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Image Zoom in and Zoom out

    Hi wang,
    But i think the scaling algorithm will amke some alterations in your image.I meant it will distort your image.

    Ashish,
    can you use two images and do the process.

    Thanks
    Soku

  6. #6
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: Image Zoom in and Zoom out

    Hi soku,

    The scaling algorithm will not make much distortion to the image. I have tried it and the result where ok. The problems faced are that it will take a little time for scaling big images. it doesn't support transperency as usual. It can't be used for very big images.

    Wang

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •