Quality of Resized Image

Discussion in 'Java' started by plank@plank.com, Aug 30, 2006.

  1. Guest

    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
    , Aug 30, 2006
    #1
    1. Advertising

  2. 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.
    Andrew Thompson, Aug 30, 2006
    #2
    1. Advertising

  3. > 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

    --
    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
    Andrey Kuznetsov, Aug 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    2
    Views:
    367
    Earl Teigrob
    Feb 20, 2004
  2. Neo Geshel
    Replies:
    3
    Views:
    1,077
    Cor Ligthert
    Jun 10, 2005
  3. =?Utf-8?B?a2Zpcg==?=

    image quality on Image control

    =?Utf-8?B?a2Zpcg==?=, Dec 14, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    352
    =?Utf-8?B?a2Zpcg==?=
    Dec 14, 2005
  4. Sean Jorden
    Replies:
    1
    Views:
    594
    laurie
    Aug 19, 2003
  5. Don
    Replies:
    29
    Views:
    963
    dorayme
    Oct 27, 2006
Loading...

Share This Page