| Reply | « Previous Thread | Next Thread » |
|
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 |
| antonio5982 |
| View Public Profile |
| Find all posts by antonio5982 |
|
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); |
|
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 |
|
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 |
| antonio5982 |
| View Public Profile |
| Find all posts by antonio5982 |
|
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. |
| prakash.raman |
| View Public Profile |
| Find all posts by prakash.raman |
|
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 |
|
yes! It works.
Thank all of you for your help! antonio |
| antonio5982 |
| View Public Profile |
| Find all posts by antonio5982 |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Opening a JPEG Image | ummarbhutta | Mobile Java Media (Graphics & Sounds) | 8 | 2007-02-15 07:34 |
| how to cut some part of Image | mshouab | Mobile Java Media (Graphics & Sounds) | 2 | 2006-08-04 10:05 |
| HELP: Mutable Image to Immutable Image? | rj_cybersilver | Mobile Java Media (Graphics & Sounds) | 1 | 2005-03-26 10:58 |
| Plz tell me easy method to cut image from the strip | mwm786 | Mobile Java General | 1 | 2005-02-01 11:12 |
| Nokia Image Converter | davidpurdie | General Discussion | 0 | 2004-02-18 16:31 |