문제

Is there a way to track changes in the pixel data of a BufferdImage? I was thinking about something like that:

PixelChangeListener listener = new PixelChangeListener() {
public void pixelchange(Event e) {
    // Get the coordinates in the Image that have been changed:
    int x=e.getX();
    int y=e.getY();
}
};
buffimage.addPixelChangeListener(listener);

If i now use g.drawLine or buffimage.setRGB(x,y,rgb); pixelchange(e) should fire.
Is there a way to do that? :)

도움이 되었습니까?

해결책

There isn't such a listener. But you could extend BufferedImage and add the APIs you need.

다른 팁

This is the solution from the OP (which was originally posted right in the question).


Not the BufferedImage itself but the WritableRaster behind it had to be modified. You can use sun.awt.image.SunWritableRaster for that, just use the notifychanged() method to track pixelchanges. To get a proper BufferedImage with the Raster I used this code:

ColorModel colormodel=ColorModel.getRGBdefault();
WritableRaster temp=colormodel.createCompatibleWritableRaster(400,400);
SunWritableRaster raster=new SunWritableRaster(temp.getSampleModel(),temp.getDataBuffer(),new Point(0,0));
BufferedImage img=new BufferedImage(colormodel,raster,true,null);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top