Name: rmT116609 Date: 06/19/2003
FULL PRODUCT VERSION :
java version "1.4.2-beta"
java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
FULL OS VERSION :
Windows 2000 SP3
A DESCRIPTION OF THE PROBLEM :
Java ImageIO incorrectly reads some JPG files, the result is a red/green image that looks somthing like a photographic negative.
Images created with "Adobe Photoshop Album" can cause this problem, but some photos are read incorrectly straight out of a digital camera.
In all cases the photos Java has problems with can be read correctly in any image editing program, or displayed correctly on any browser.
The code necessary to produce the error is as simple as:
File inFile = new File(inname);
BufferedImage im = ImageIO.read(inFile);
File outFile = new File(outname);
ImageIO.write(im, "jpg", outFile);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
File inFile = new File(inname);
BufferedImage im = ImageIO.read(inFile);
File outFile = new File(outname);
ImageIO.write(im, "jpg", outFile);
An example of a JPG that JAVA cannot read is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207.jpg
The photo that JAVA produced from this image is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207_S.jpg
I can provide you with many more samples of JPG files that Java cannot read correctly if you wish.
Steps to reproduce the problem:
-------------------------------
I call this program with
java makeSmall 480 c:\MistyMorn-334229207.jpg c:\MistyMorn-334229207_S.jpg 640
This means that I want to read the photo file "C:\MistyMorn-334229207.jpg"
and create a new file called "C:\MistyMorn-334229207_S.jpg"
which has a height of 480 pixels unless that would make the width wider than 640, in which case the height is reduced.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JPG file created should display correctly, but instead it has mostly red/green colours, and looks like a photographic negative
ACTUAL -
An example of a JPG that JAVA cannot read is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207.jpg
The photo that JAVA produced from this image is here:
www.PhotoShare.co.nz/PhotoShareGallery1/100041/101268/MistyMorn-334229207_S.jpg
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import javax.imageio.event.*;
import javax.imageio.stream.*;
public class makeSmall
{
public static void main(String[] args){
if (args.length < 4) {
System.out.println("Usage: java makeSmall height infile outfile maxwidth");
System.exit(0);
}
try {
int newH = Integer.valueOf(args[0]).intValue();
int maxW = Integer.valueOf(args[3]).intValue();
String inname = args[1];
String outname = args[2];
File inFile = new File(inname);
BufferedImage im = ImageIO.read(inFile);
double w = im.getWidth();
double h = im.getHeight();
double scaleRatio = newH/h ;
if (scaleRatio > 1){
scaleRatio = 1;
}
if (w * scaleRatio > maxW){
scaleRatio = maxW/w;
}
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scaleRatio, scaleRatio),null);
/*AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(xratio, yratio),2);*/
BufferedImage scaledIm = op.filter(im,null);
File outFile = new File(outname);
ImageIO.write(scaledIm, "jpg", outFile);
} catch(IOException ioe){
/*System.out.println("Error reading or writing file");*/
System.exit(2);
} catch(Exception e){
/*System.out.println("Error scaling image");*/
System.exit(3);
}
}
}
---------- END SOURCE ----------
(Review ID: 187571)
======================================================================