mortennobel / java-image-scaling

Automatically exported from code.google.com/p/java-image-scaling
Other
130 stars 41 forks source link

ArrayIndexOutOfBoundsException 1924 #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Using photo attached
2.Creating a image using: DimensionConstrain dc
=DimensionConstrain.createMaxDimension(604,604, true);
3.Run test program

What is the expected output? What do you see instead?
expected resized photo but get Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 1924

What version of the product are you using? On what operating system?
0.8.2

Please provide any additional information below.

Original issue reported on code.google.com by charleskailunglee@gmail.com on 3 Nov 2009 at 9:54

Attachments:

GoogleCodeExporter commented 9 years ago
I'm unable to reproduce the problem in 0.8.2 (just released). I suspect the 
error
report is about 0.8.1 (even though is says 0.8.2).
I case I'm wrong, please provide me with a full code example (I'm currently 
using the
one below):

BufferedImage image2D = 
ImageIO.read(getClass().getResourceAsStream("issue11.jpg"));
DimensionConstrain dc = DimensionConstrain.createMaxDimension(604,604, true);
ResampleOp  resampleOp = new ResampleOp (dc);
BufferedImage rescaledTomato = resampleOp.filter(image2D, null);

Original comment by m%nobel-...@gtempaccount.com on 3 Nov 2009 at 2:42

GoogleCodeExporter commented 9 years ago
I downloaded 8.3 jar and works with no exception now. However the rescaling 
seem to
have reduce some quality of the original. I have attached the rescaled of the
previous attached photo. There are extra white shadow around the white part of 
the
picture which dont exist from the original.

Here is the code i use:

BufferedImage bi = ImageIO.read(src);

         DimensionConstrain dc =DimensionConstrain.createMaxDimension(604,604, true);
       ResampleOp resampleOp = new ResampleOp(dc);

            resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Soft);
            BufferedImage rescaled = resampleOp.filter(bi,null);

             File outfile = new File("/Users/charlie/Development/java/playSe/"+ file
+".jpg");
            javax.imageio.ImageIO.write(rescaled, "jpg", outfile);

Original comment by charleskailunglee@gmail.com on 5 Nov 2009 at 10:08

Attachments:

GoogleCodeExporter commented 9 years ago
Ok. It seems to be a problem. It must be related to the file format (Grayscale
jpegs). If the source image is saved as png, there is no problem.

The wierd thing is that in my IDE (IntelliJ) there is actually also white noise 
on
the source image as well.

I'll look at it.

Original comment by m%nobel-...@gtempaccount.com on 11 Nov 2009 at 8:19

GoogleCodeExporter commented 9 years ago
I figured out what is wrong. The rescale works as intended - the white shadows 
is
created by the jpeg compression.

To fix it simply choose a lossless format (such as png) or increase the jpeg 
quality
using the following code:
private void saveHighqualityJpeg(BufferedImage rescaledTomato, String filename)
throws IOException {
        ImageWriter writer = null;
        Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
        if (iter.hasNext()) {
            writer = (ImageWriter)iter.next();
        }

        FileOutputStream fos = new FileOutputStream(filename);
        ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        writer.setOutput(ios);
        ImageWriteParam iwparam = writer.getDefaultWriteParam();
        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
        System.out.println(iwparam.getCompressionQuality()) ;
        iwparam.setCompressionQuality(1.0f) ;
        writer.write(null, new IIOImage(rescaledTomato, null, null), iwparam);
        writer.dispose();
        ios.close();
        fos.close();
    }

Original comment by m%nobel-...@gtempaccount.com on 29 Dec 2009 at 7:19