Skip to main content

Rendering a color fax (.tif) displays a green tint

1 reply [Last post]
dbrandley
Offline
Joined: 2008-08-13
Points: 0

I am trying to open and display a tiff file and it has a green tint. If I open the file using Brava Reader the file displays the correct colors. Some other readers display it in green tint.

TIA, I appreciate any help on this.

private BufferedImage openPage(int index, boolean subsample) {
BufferedImage bufferedImage = null;
ImageReader reader = null;
ImageInputStream stream = null;

try {
stream = ImageIO.createImageInputStream(new File("c:\\c03x_02x.tif"));

if (stream == null) {
return null;
}

Iterator iter = ImageIO.getImageReaders(stream);
if (!iter.hasNext()) {
return null;
}

while(iter.hasNext()) {
reader = iter.next();
reader.setInput(stream, true, true);

ImageReadParam param = reader.getDefaultReadParam();
if (subsample) {
param.setSourceSubsampling(2,2,0,0);
}

RenderedImage image = reader.readAsRenderedImage(this.currentPage, param);
bufferedImage = this.convertRenderedImage(image);
}
} catch (IOException e) {
log.error("Failed to open image with reader: " + reader, e);
bufferedImage = null;
} catch (ArrayIndexOutOfBoundsException e) {
log.error("Failed to open image with reader: " + reader, e);
bufferedImage = null;
} finally {
if(stream != null) {
try {
stream.close();
} catch (IOException e) {
log.debug("Failed to close input stream.", e);
}
}

if(reader != null) {
reader.dispose();
}
}

return bufferedImage;
}

----

private BufferedImage convertRenderedImage(RenderedImage img) {
RenderedImageAdapter adapter = new RenderedImageAdapter(img);
return adapter.getAsBufferedImage();
}

----

public JLabel getContent(BufferedImage image) {
this.image = image;
label = new JLabel(new ImageIcon(getScaledImage(this.scale/100.0)));
label.setHorizontalAlignment(JLabel.CENTER);
return label;
}

----

private BufferedImage getScaledImage(double scale) {
int w = (int) (scale * image.getWidth());
int h = (int) (scale * image.getHeight());
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
g2.drawRenderedImage(image, at);
g2.dispose();
return bi;
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcojacob
Offline
Joined: 2006-07-10
Points: 0

It might depend on the kind of TIFF you have for input. It might be CMYK TIFF.
Then you might get strange colours when you try to draw it to RGB.
Maybe you need to transform the image to RGB first.

AFAIK there is nothing like a color fax format. Can you provide some meta information
about the tiff file?