Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Quality of Resized Image

Thread view: 
plank@plank.com - 30 Aug 2006 14:03 GMT
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
Andrew Thompson - 30 Aug 2006 14:27 GMT
...
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.
Andrey Kuznetsov - 30 Aug 2006 14:34 GMT
> 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
[quoted text clipped - 10 lines]
> 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

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.