如何检索 tiff 图像中的像素(用 JAI 加载)?

发布于 2024-09-03 16:30:23 字数 1249 浏览 10 评论 0原文

我正在使用一个类(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半﹌身腐败 2024-09-10 16:30:23

如果 source是一个BufferedImage,您可以使用getRGB(),如图此处

If the source is a BufferedImage, you can use getRGB(), as shown here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文