1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import java.awt.image.BufferedImage;
import java.awt.image.Raster;
public class Image {
public final BufferedImage bimg;
public Image(BufferedImage bimg) { this.bimg = bimg; }
public int getWidth() { return bimg.getWidth(); }
public int getHeight() { return bimg.getHeight(); }
public int getValue(int x, int y) {
Raster raster = bimg.getData();
if (raster.getNumBands()>=3)
return (299*raster.getSample(x,y,0)+587*raster.getSample(x,y,1)+114*raster.getSample(x,y,2))/1000;
else return raster.getSample(x, y, 0);
}
} |
Partager