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

Posted by Ed Taylor on Stack Overflow See other posts from Stack Overflow or by Ed Taylor
Published on 2010-05-30T16:44:56Z Indexed on 2010/05/30 16:52 UTC
Read the original article Hit count: 501

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about jai