如何检索 tiff 图像中的像素(用 JAI 加载)?
我正在使用一个类(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 值?
I'm using a class (DisplayContainer) to hold a RenderedOp-image that should be displayed to the user:
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);
The class DisplayContainer looks like this:
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
}
What I would like to know is how the RGB value of the clicked pixel can be obtained?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
source
是一个BufferedImage
,您可以使用getRGB()
,如图此处。If the
source
is aBufferedImage
, you can usegetRGB()
, as shown here.