views:

29

answers:

2

I have a scanned image that I'm viewing in a java applet. The image is in a jpeg format. When I look at the same image in Internet Explorer, it looks sharper. I would like to make the image quality in my application be as sharp as what I'm seeing in IE. Any ideas on how to sharpen the image rendered in java?

Thanks,

Elliott

+1  A: 

I seriously doubt that IE actively sharpens the image, so probably what's happening is you're displaying the image in your applet in such a way as to degrade the quality (probably scaling it). Could you post some code?

Neil Coffey
It turns out that it was a simple scaling problme as Neil Coffey suggested. Thank you for pointing me in the right direction. Elliott
Elliott
A: 

Considering this is a scanned image, i assume its a document of some sort most likely containing text. I believe IE uses a bilinear sampling algorithm by default for scaling images which may produce better results for these kinds of images. In any case you will need to modify your scaling algorithm when you render the image to ensure proper quality.

here's a simple example that shows setting the scaling algorithm to be Bilinear, this may or may not give you the correct results, i would keep trying with different algorithms until you get the correct results. (see RenderingHints and look for settings starting with `VALUE_INTERPOLATION_...")

private float xScaleFactor, yScaleFactor = ...; private BufferedImage originalImage = ...;

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
    int newW = (int)(originalImage.getWidth() * xScaleFactor);
    int newH = (int)(originalImage.getHeight() * yScaleFactor);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.drawImage(originalImage, 0, 0, newW, newH, null);
}

Also check out this article for some insight into various performance concerns and use to make sure everything is working well.

luke