0

我正在使用一个类(DisplayContainer)来保存应该向用户显示的 RenderedOp-image:

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值?

4

1 回答 1

0

如果source是a BufferedImage,则可以使用,getRGB()如图所示

于 2010-05-30T17:45:16.783 回答