aspose file tools
The moose likes Java Micro Edition and the fly likes Can we resize the image in j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Mobile » Java Micro Edition
Reply Bookmark "Can we resize the image in j2me " Watch "Can we resize the image in j2me " New topic
Author

Can we resize the image in j2me

Praveen india
Greenhorn

Joined: Feb 23, 2005
Posts: 7
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

Joined: Mar 07, 2002
Posts: 1427
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.


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Jari Kemppinen
Ranch Hand

Joined: Nov 28, 2004
Posts: 34
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

Joined: Feb 23, 2005
Posts: 7
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

Joined: Feb 24, 2005
Posts: 2
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

Joined: Nov 28, 2004
Posts: 34
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

Joined: Feb 24, 2005
Posts: 2
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
ApxA Corporation
Greenhorn

Joined: May 14, 2005
Posts: 1
Hello,
I try your sample about resize but i use it in a streaming jpg mode and i wonder if we can optimized the code to speed up.
The process with "for" in "for" lose time with an image (320x240)
Best regards,
LuisMiguel Rubio
Greenhorn

Joined: Jul 27, 2005
Posts: 1
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

Joined: Dec 13, 2010
Posts: 2
Thanks LuisMiguel,

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

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11740

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!


A lot the of modern-day software development platforms are designed to permit parcelling out work to those with the best aptitude for it. A lot of modern-day business is predicated on making one person do all the work, regardless of aptitude.
Mark Cowan
Greenhorn

Joined: Dec 13, 2010
Posts: 2
Tim - that's okay. It's import to thank him and to let other's know that his code works well.
swaroop venu
Greenhorn

Joined: Jan 05, 2011
Posts: 3
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;
}

This message was edited 1 time. Last update was at by swaroop venu

swaroop venu
Greenhorn

Joined: Jan 05, 2011
Posts: 3
swaroop venu wrote:Thanks LuisMiguel, it works great...
swaroop venu
Greenhorn

Joined: Jan 05, 2011
Posts: 3
Dhanushka Nayanananda
Greenhorn

Joined: Jan 16, 2011
Posts: 13
Ya. .. It s perfect.. Thank you very much
 
 
subject: Can we resize the image in j2me
 
Two Laptop Bag