public static Image resizeImage(Image src, int screenWidth, int screenHeight)
{
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
Image tmp = Image.createImage(screenWidth, srcHeight);
Graphics g = tmp.getGraphics();
int ratio = (srcWidth << 16) / screenWidth;
int pos = ratio / 2;
// Horizontal Resize
for (int x = 0; x < screenWidth; x++)
{
g.setClip(x, 0, 1, srcHeight);
g.drawImage(src, x - (pos >> 16), 0, Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
Image resizedImage = Image.createImage(screenWidth, screenHeight);
g = resizedImage.getGraphics();
ratio = (srcHeight << 16) / screenHeight;
pos = ratio / 2;
//Vertical resize
for (int y = 0; y < screenHeight; y++) {
g.setClip(0, y, screenWidth, 1);
g.drawImage(tmp, 0, y - (pos >> 16), Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
return resizedImage;
}
Apr 10, 2008
[J2ME] Resize an Image Object
Posted by Heriman under programming | Tags: j2me, programming |[5] Comments
Mar 19, 2009 at 5:25 pm
v v thanks,ur code is v help full to me.
May 26, 2009 at 2:28 pm
Thanks.
I solved my problem due to your code.
Thanks again.
Jul 16, 2009 at 11:40 pm
Thanks in advance…
was very use full…
Jul 30, 2009 at 1:00 pm
thanks.
Oct 22, 2009 at 10:13 pm
Thanks a lot) Suits me just fine))