开发者

How to retrieve a pixel in a tiff image (loaded with JAI)?

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 Dis开发者_如何学运维playJAI {

    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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜