Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to display a TIFF Page on a JLabel, setting it as a icon. But it displays black image but the size is the same I guess. Anyone know whats the problem?
Java
FileSeekableStream ss = new FileSeekableStream(filename);
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
RenderedImage page = dec.decodeAsRenderedImage(0);

this.label = new JLabel();
this.label.setIcon(new ImageIcon(ConvertRenderedImage(page)));

public BufferedImage ConvertRenderedImage(RenderedImage img) {
    if (img instanceof BufferedImage) {
		return (BufferedImage)img;  
	}   
	ColorModel cm = img.getColorModel();
	int w = img.getWidth();
	int h = img.getHeight();
	WritableRaster raster = cm.createCompatibleWritableRaster(w, h);
	boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	Hashtable properties = new Hashtable();
	String[] keys = img.getPropertyNames();
	if (keys!=null) {
		for (String key : keys) {
			properties.put(key, img.getProperty(key));
		}
	}
	BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
	img.copyData(raster);
	return result;
}
Posted
Updated 2-Feb-15 22:01pm
v4
Comments
Richard MacCutchan 23-Jan-15 11:49am    
I don't know if there's a syntax for a commit in ImageIO
What does the documentation say?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900