File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we resize the image in j2me

 
Praveen india
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we resize the image in j2me so that bigger dimention image can fit into
the mobile screen.
My actual task in to zoom in and out the image
[ February 23, 2005: Message edited by: Praveen india ]
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot resize the in-memory image unless you understand the encoding algorithm. But when you draw the image on screen, you can map each screen pixel to several pixels on the image -- effectively smooth it and reduce its display size.
 
Jari Kemppinen
Ranch Hand
Posts: 34
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a piece of code I use to display a resized image. Hope it helps.



Let's make this great code more readable using CODE tags. - Mark
[ May 15, 2005: Message edited by: Mark Spritzler ]
 
Praveen india
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jari Kemppinen for this code,
Now my problem is that when I make bigger picture to Thumbnail image
it works fine, the quality of picture is also good,
but when I use the same method in which I passed Thumbnail image as
parameter and changed the thumbWidth,thumbHeight values,to get the bigger
image the quality of picture is not good.
But if I use the original image to fit the screen I am getting java.lang.OutOfMemoryError if the image is bigger the screen size.
if the image is small the screen size, so the error dosen't cum
can u help me
[ February 24, 2005: Message edited by: Praveen india ]
 
Nitin India
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jari,

tht code was really gud, but i have one query when i tried this code on transparent image it showed me white pixels on transparent area.

can i remove these these white pixels.

thnks
 
Jari Kemppinen
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I can't help you guys any further, haven't got time to look into the problems you are having. If you find a solution please post it up to help other people with similar problems.
 
Nitin India
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all..

can any one help. i hv same question which i asked in my previous post.

though i hv done few things but was unsuccessful. its related to changing a alpha channel in a png image using nokia UI API.

can some one help.

thnks
 
LuisMiguel Rubio
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. Thanks for your code. I've created other faster than yours, but i think it could be faster with some changes. And the more important, can resize images with transparent pixels.

It works with RGBArrays. First, we need a function to resize Arrays:



INI: Source Array
X: Width of Source Array
Y: Height of Source Array
X2: Width of the Output Array
Y2: Height of the Output Array
Returns OUT (Output Array)

How to use it:



Et voil´┐Ż. Next, i will modify a bit the "reescalaArray" function to improve more speed. If you get better results, please, share the solution

Happy summer!!

PD: Sorry my English, but i am Spanish
[ July 27, 2005: Message edited by: LuisMiguel Rubio ]
 
Mark Cowan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks LuisMiguel,

Your code works perfectly. It really solves the problem of how to resize an image.

 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Mark!

You've "awakened a zombie". LuisMiguel posted that message 5 years ago. In this business that means that he's probably gone on to at least 2 other employers since he posted. And that's assuming he didn't quit the profession entirely.

We're glad that this thread was helpful to you, but I wouldn't count on LuisMiguel answering you!
 
Mark Cowan
Greenhorn
Posts: 2
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim - that's okay. It's import to thank him and to let other's know that his code works well.
 
swaroop venu
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks LuisMiguel, it works great...i have modified a bit..to make it faster also helps in freeing up memory


Image image1=reescalaArray(image,image.getWidth(),image.getHeight(),newX,newY);

Image reescalaArray(Image temp, int x, int y, int x2, int y2) {
int ini[] = new int[temp.getWidth()*temp.getHeight()];
//Get the RGB array of image into "rgb"

int i=0,t2;
int dy,dx;
temp.getRGB(ini,0,temp.getWidth(),0,0,temp.getWidth(),temp.getHeight());
int out[] = new int[x2*y2];
//t1=y/y2;
t2=x/x2;
for (int yy = 0; yy < y2; yy++) {
dy = yy *y/y2;

for (int xx = 0; xx < x2; xx++) {
dx = xx * t2;

out[i++]=ini[(x*dy)+dx]; //(x2*yy)+xx
}
}
Image temp3 = Image.createRGBImage(out,getWidth(),getHeight(),true);
return temp3;
}
 
swaroop venu
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
swaroop venu wrote:Thanks LuisMiguel, it works great...
 
swaroop venu
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dhanushka Nayanananda
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya. .. It s perfect.. Thank you very much
 
Razvan Cotty
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
Thank you for the code, it was extremely useful. However, I have noticed that on some phones it does not work if the image is very large as it has to create a huge array. So I have come up with an optimized version:



What's good about it is that it loads the original image line by line and depending on the ratio it skips the lines from the original image that are not needed for the resize process.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Razvan Cotty welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic