dragon66 / java-image-scaling

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

Error scaling png, still not working #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download the following image and try resizing it:
http://www.dirnat.no/multimedia.ap?id=718
The result can be seen here:
http://www.dirnat.no/multimedia.ap?id=718&width=590&height=590

What is the expected output? What do you see instead?
Should be a normal scaled image, but the colors get all twisted and weird
like the previous png bug you fixed on Dec 27 2009

What version of the product are you using? On what operating system?
Using version 0.8.4 on windows (all platforms)

Please provide any additional information below.
Tested the resizing in the online version
(http://www.nobel-joergensen.com/java/projects/easizer/) and it fails to
resize the image. Nothing is produced

Original issue reported on code.google.com by tros...@gmail.com on 26 Mar 2010 at 11:09

GoogleCodeExporter commented 9 years ago
Unable to reproduce (However not that the Easizer is not up-to-date!)

I have attached a testcase (with version 0.8.4 downloaded from 
http://code.google.com/p/java-image-scaling/ ) that works on my machine.

Please let me know if you still have problems.

Original comment by m%nobel-...@gtempaccount.com on 26 Mar 2010 at 7:33

Attachments:

GoogleCodeExporter commented 9 years ago
I'm using version 0.8.4 and experienced the same problem.

 int maxheightwidth  = 150;
                BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
            int width = img.getWidth();
            int height = img.getHeight();

            if (height > maxheightwidth || width > maxheightwidth) {
                if (height > width) {
                    // height > width
                    float ratio = (float) maxheightwidth / height;
                    height = maxheightwidth;
                    width = (int) (ratio * width);
                } else {
                    float ratio = (float) maxheightwidth / width;
                    width = maxheightwidth;
                    height = (int) (ratio * height);
                }

                // image = image.scaleImage(width, height);

            }

            ResampleOp resampleOp = new ResampleOp(width, height);
            resampleOp.setNumberOfThreads(4);

            resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
            BufferedImage rescaledImage = resampleOp.filter(img, null);

            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ImageIO.write(rescaledImage, this.format.toLowerCase(), b);

            data = b.toByteArray();

Original comment by tbr...@gmail.com on 15 Apr 2010 at 10:53

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the feedback. 

What version of Java are you using? And on what platform?

Original comment by m%nobel-...@gtempaccount.com on 16 Apr 2010 at 5:58

GoogleCodeExporter commented 9 years ago
I tested this on debian (64 bit):

java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)

and on my local windows 7 machine (64bit):
jdk1.6.0_19 (32 bit as I only had 32 bit imagemagick ddl available)

Original comment by tbr...@gmail.com on 16 Apr 2010 at 12:37

GoogleCodeExporter commented 9 years ago
I can reproduce it with the following test case. If you output the rescaled 
image as
png, the problem doesn't occur!

I also ran this in a fresh project (with only the filter, junit and 
image-scaling
library), so it's definitely not some jar library conflict.

Original comment by tbr...@gmail.com on 16 Apr 2010 at 1:40

Attachments:

GoogleCodeExporter commented 9 years ago
I'm pretty sure that the problem only occur if both rescale the image and 
change from
one image type to another. 

Original comment by m%nobel-...@gtempaccount.com on 16 Apr 2010 at 2:11

GoogleCodeExporter commented 9 years ago
I can confirm that keeping same image format is reasonable workaround, and to 
get format name just use the following code: 

ByteArrayInputStream byteInputStream = new ByteArrayInputStream(img.imgData);
ImageInputStream imageInputStream = 
ImageIO.createImageInputStream(byteInputStream);
Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
BufferedImage bigImg = ImageIO.read(imageInputStream);
String formatName;
if(imageReaders.hasNext())
    {
    ImageReader imageReader = imageReaders.next();
    formatName = imageReader.formatName;
}

Original comment by marcin.l...@gmail.com on 21 Nov 2010 at 10:06

GoogleCodeExporter commented 9 years ago
I'm closing this bug, since I believe the bug relates to the ImageIO more than 
ImageScaling library. 

Original comment by m%nobel-...@gtempaccount.com on 5 Feb 2011 at 1:43

GoogleCodeExporter commented 9 years ago
So if someone has to do it how can it be done?

Original comment by vramd...@gmail.com on 20 Apr 2011 at 9:14

GoogleCodeExporter commented 9 years ago
You can use the workaround suggested by marcin:
http://code.google.com/p/java-image-scaling/issues/detail?id=18#c7

Original comment by m%nobel-...@gtempaccount.com on 20 Apr 2011 at 7:04