O
Oliver
Hi,
I've googled around and found some references to CMYK color space, but
nothing which would indicate a solution to my problem: I'm reading an
image (png, jpeg, ...), scale it with an AffineTransformOp and save it
again as JPEG into a file.
Problem: the resulting JPEG file has wrong colours, red goes to light
blue, white goes to reddish, light blue goes to green etc. (note: the
colors are _not_ just inverted, they look like CMYK colors, but
displayed as RGB values (?)).
Now when I _don't_ scale the image, but simply read it and save it as
JPEG then everything is okay! What's more, when I scale it but change
the output format to PNG the image looks good as well!
Here's the code:
BufferedImage image = ImageIO.read (new File (inputImagePath));
AffineTransform tx = new AffineTransform();
tx.scale (x, y);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_BILINEAR);
BufferedImage scaledImage = op.filter(image,
op.createCompatibleDestImage(image,
ColorModel.getRGBdefault()));
ImageIO.write(image, "jpeg", imageFile);
I've also simply tried:
BufferedImage scaledImage = op.filter(image, null);
The debug output message says:
System.out.println ("Color model: " +
scaledImage.getColorModel().toString());
"Color model: DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff
amask=ff000000"
That should indicate that the transformation calculates in RGB space,
no?
I've tried several input images (jpg, png) and also created a test
input jpg images which I'm sure is stored in RGB format (not CMYK). The
original (unscaled) images are also displayed fine in some JLabel...
Do I have to explicitly set some JPEG encoder paramters as to enforce
the proper color model? What's going wrong?
I'm using the jdk1.5.0_04 on Windows XP
Thanks, Oliver
I've googled around and found some references to CMYK color space, but
nothing which would indicate a solution to my problem: I'm reading an
image (png, jpeg, ...), scale it with an AffineTransformOp and save it
again as JPEG into a file.
Problem: the resulting JPEG file has wrong colours, red goes to light
blue, white goes to reddish, light blue goes to green etc. (note: the
colors are _not_ just inverted, they look like CMYK colors, but
displayed as RGB values (?)).
Now when I _don't_ scale the image, but simply read it and save it as
JPEG then everything is okay! What's more, when I scale it but change
the output format to PNG the image looks good as well!
Here's the code:
BufferedImage image = ImageIO.read (new File (inputImagePath));
AffineTransform tx = new AffineTransform();
tx.scale (x, y);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_BILINEAR);
BufferedImage scaledImage = op.filter(image,
op.createCompatibleDestImage(image,
ColorModel.getRGBdefault()));
ImageIO.write(image, "jpeg", imageFile);
I've also simply tried:
BufferedImage scaledImage = op.filter(image, null);
The debug output message says:
System.out.println ("Color model: " +
scaledImage.getColorModel().toString());
"Color model: DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff
amask=ff000000"
That should indicate that the transformation calculates in RGB space,
no?
I've tried several input images (jpg, png) and also created a test
input jpg images which I'm sure is stored in RGB format (not CMYK). The
original (unscaled) images are also displayed fine in some JLabel...
Do I have to explicitly set some JPEG encoder paramters as to enforce
the proper color model? What's going wrong?
I'm using the jdk1.5.0_04 on Windows XP
Thanks, Oliver