我正在使用一个类(DisplayContainer)来保存应该向用户显示的RenderedOp图像:
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值?