Quality of Resized Image

P

plank

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
 
A

Andrew Thompson

(e-mail address 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.
 
A

Andrey Kuznetsov

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_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

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

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

Andrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top