如何检索tiff图像中的像素(使用JAI加载)?
问题描述:
我使用一个类(DisplayContainer)持有应显示给用户的RenderedOp图像:如何检索tiff图像中的像素(使用JAI加载)?
RenderedOp image1 = JAI.create("tiff", params);
DisplayContainer d = new DisplayContainer(image1);
JScrollPane jsp = new JScrollPane(d);
// Create a frame to contain the panel.
Frame window = new Frame();
window.add(jsp);
window.pack();
window.setVisible(true);
类DisplayContainer看起来是这样的:
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import javax.media.jai.RenderedOp;
import com.sun.media.jai.widget.DisplayJAI;
public class DisplayContainer extends DisplayJAI {
private static final long serialVersionUID = 1L;
private RenderedOp img;
// Affine tranform
private final float ratio = 1f;
private AffineTransform scaleForm = AffineTransform.getScaleInstance(ratio, ratio);
public DisplayContainer(RenderedOp img) {
super(img);
this.img = img;
addMouseListener(this);
}
public void mouseClicked(MouseEvent e) {
System.out.println("Mouseclick at: (" + e.getX() + ", " + e.getY() + ")");
// How to retrieve the RGB-value of the pixel where the click took
// place?
}
// OMISSIONS
}
我想要知道点击像素的RGB值是如何获得的?
我不确定你的意思是来源,但RenderedOp实现RenderedImage – 2010-05-30 18:05:02
'source'是'DisplayContainer'中的一个字段,继承自DisplayJAI'。如果你将'DisplayContainer'提供给'BufferedImage',它就会在那里等着你。 – trashgod 2010-05-30 18:15:23
源字段是RenderedImage。 tiff图片可以表示为BufferedImage吗? BufferedImage img = ImageIO.read(new File(“low.tiff”));不起作用... – 2010-05-30 19:47:42