×

Discussion Board

Results 1 to 7 of 7

Thread: Cut an image

  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    88

    Cut an image

    Hi everybody!
    I would like to ask you if I can create a new image from another big image. I don't want to resize the image in a small image but I would like to have a new image which is part of the previous one. So it means that if I have an image bigger 300x300, I want to create a image 200x300, so I will cut the rest..... is it possible to create this image? how?

    thanks in advance

    antonio

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: Cut an image

    Yes, you can "cut" the big image and create a smaller one. The standard MIDP 2.0 Image object (http://java.sun.com/javame/reference...dui/Image.html) has a method called getRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height). It also has a method called createRGBImage(int[] rgb, int width, int height, boolean processAlpha), which will allow you to create a new image up on previously extracted RGB data.

    So, for your case the code would look like:

    int[] rgb_data = new int[200 * 300];

    big_image.getRGB(rgb_data, 0, 200, 0, 0, 200, 300);

    Image smaller_image = Image.createRGBImage(rgb_data, 200, 300, true);

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: Cut an image

    If you don't care about transparency then you can also simply use Image.createImage(width, height) and draw the bigger image onto the new empty image. This is MIDP 1.0, so it will ease porting.

    shmoove

  4. #4
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    88

    Re: Cut an image

    thank you for your reply!

    But I have still some problem to create this image.... I hope that you can help me....I will try to specify the problem:

    Image image = Image.createImage(....);
    int widht = image.getWidth();
    int heght = image.getHeigth();

    Now I want to create a new image, which should have the same width, but smaller height. What I mean is that I want to cut off the top of the picture - I dont want to show the first 84 pixels of height.... so it will be the same image but starting from the 85th pixel...

    thanks again for your help

    antonio

  5. #5
    Super Contributor
    Join Date
    Jun 2007
    Location
    Mumbai
    Posts
    539

    Re: Cut an image

    Hey antonio,
    surely u can do this, use this api..

    javax.microedition.lcdui.Image.createImage(Image image, int x, int y, int width, int height, int transform)

    this takes ur first image as input and creat the new image using the height width that u want.

    check its details in java doc.

  6. #6
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: Cut an image

    Just my 2 cents in what prakash.raman wrote. Try the next code:

    Image smaller_image = Image.createImage(big_image, 0, 85, big_image.getWidth(), big_image.getHeight() - 85, Sprite.TRANS_NONE);

    This should create a new image which will have the same width as a big one, and 85 pixels less in height. Note, that the Sprite class is defined in the package javax.microedition.lcdui.game

  7. #7
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    88

    Re: Cut an image

    yes! It works.
    Thank all of you for your help!

    antonio

Similar Threads

  1. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  2. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  3. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  4. Plz tell me easy method to cut image from the strip
    By mwm786 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-02-01, 10:12
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

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