Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Quality of Resized Image

Reply
Thread Tools

Quality of Resized Image

 
 
plank@plank.com
Guest
Posts: n/a
 
      08-30-2006
Hi,

I am a newbie in Java and am trying to resize an image through a Java Applet. The code I am using works fine, however the
quality of the image is quite poor.

Code is:

public static BufferedImage ResizeImage(BufferedImage buffImg, String sType)
{
Dimension dimSize = GetImageSize(new Dimension(buffImg.getWidth(), buffImg.getHeight()), sType);

Image img = buffImg.getScaledInstance(dimSize.width, dimSize.height, BufferedImage.SCALE_SMOOTH);
BufferedImage buffNew = new BufferedImage(dimSize.width, dimSize.height, buffImg.getType());
Graphics g = buffNew.getGraphics();
g.drawImage(img, 0, 0, null);

return buffNew;
}

Can anyone give me some pointers on how to make the quality better?

Any help would be greatly appreciated!

Thanks in advance!

Anil

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-30-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
....
Please put line breaks at around 60-70 characters. News-readers
do not deal well with very wide lines, especially after the text
is 'quoted'.

> I am a newbie in Java and am trying to resize an image through a Java Applet. The code I am using works fine, however the
> quality of the image is quite poor.


Define 'fine', define 'poor'? But instead of using words, give us
a link to some *screenshots*. A picture paints a thousand words.

>
> Code is:
>
> public static BufferedImage ResizeImage(BufferedImage buffImg, String sType)


Also please change 'tabs' in code to spaces, otherwise..

> {
> Dimension dimSize = GetImageSize(new Dimension(buffImg.getWidth(), buffImg.getHeight()), sType);
>
> Image img = buffImg.getScaledInstance(dimSize.width, dimSize.height, BufferedImage.SCALE_SMOOTH);


Image img=...

....lines can also become ridiculously wide.
.....
> Can anyone give me some pointers on how to make the quality better?


'Depends' on the type of graphic. An algorithm that is good for
resizing images with lots of color gradients might be terrible for
resizing 'line drawings'. Which brings us back to..

screenshots? Note that you do not need to make them
big in pixel size, and can probably drop them to a low
number of colors to further reduce the disk size, while still
showing the deterioration you need to show.

Andrew T.

 
Reply With Quote
 
 
 
 
Andrey Kuznetsov
Guest
Posts: n/a
 
      08-30-2006
> I am a newbie in Java and am trying to resize an image through a Java
> Applet. The code I am using works fine, however the
> quality of the image is quite poor.
>
> Code is:
>
> public static BufferedImage ResizeImage(BufferedImage buffImg, String
> sType)
> {
> Dimension dimSize = GetImageSize(new Dimension(buffImg.getWidth(),
> buffImg.getHeight()), sType);
>
> Image img = buffImg.getScaledInstance(dimSize.width, dimSize.height,
> BufferedImage.SCALE_SMOOTH);

you are mixing here old imaging model with new - getScaledInstance do *load*
image again,
this is surely not what you want, especialy if you know that BufferedImage
buffers all pixels,
so no need to ask ImageProducer to resend them.

> BufferedImage buffNew = new BufferedImage(dimSize.width, dimSize.height,
> buffImg.getType());


Graphics2D g2d = buffNew.createGraphics();
g2D.setRenderingHint(RenderingHints.KEY_INTERPOLAT ION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

//create appropriate AffineTransform (scale):
AffineTransform xform = AffineTransform.getScaleInstance(...);

//and draw image with
g.drawImage(buffImg, xform, null);

Andrey

--
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Image not resized to browser window Don HTML 29 10-27-2006 02:51 AM
Did I do this correctly? - Display resized image from DB. Neo Geshel ASP .Net 3 06-10-2005 10:41 AM
Rebinding page after image is resized on server not showing new sized image Earl Teigrob ASP .Net 2 02-20-2004 09:44 PM
Bigger image size and lower quality vs. Smaller image size and higher quality Desmond Digital Photography 5 09-27-2003 04:08 AM
Re: resized image in table extends table width to original image width Sean Jorden HTML 1 08-19-2003 08:59 AM



Advertisments