tags:

views:

114

answers:

1

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?

A: 

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

trashgod
I'm not sure what you mean by source but RenderedOp implements RenderedImage
Ed Taylor
`source` is a field in `DisplayContainer`, inherited from `DisplayJAI `. If you feed `DisplayContainer` a `BufferedImage`, it'll be there waiting for you.
trashgod
The source field is a RenderedImage. Can a tiff picture be represented as a BufferedImage? BufferedImage img = ImageIO.read(new File("low.tiff")); doesn't work...
Ed Taylor
Works for me with `MARBLES.TIF` et al. http://www.fileformat.info/format/tiff/sample/index.htm
trashgod
OK, I get a java.lang.NullPointerException. TIF is also not mentioned as a supported format according to: http://java.sun.com/docs/books/tutorial/2d/images/loadimage.html
Ed Taylor
You might try `ImageIO.getReaderFileSuffixes()`. This may be related to your previous question, http://stackoverflow.com/questions/2926517
trashgod