How to take an image file and convert it to a raster, and then access its data (RBG values) in pixels?
BufferedImage img = ImageIO.read(new File("lol")); int rgb = img.getRGB(x, y); Color c = new Color(rgb);
Now you can use Color.getRed (), getGreen (), getBlue () and getAlpha () to get different values
BufferedImage image = ImageIO.read(new File(myFilename)); int pixel = image.getRGB(0, 0); // Top left pixel. // Access the color components, valued 0-255. int alpha = (pixel >>> 24) & 0xff; // If applicable to image format. int r = (pixel >>> 16) & 0xff; int g = (pixel >>> 8) & 0xff; int b = pixel & 0xff;
[] , @Sibbo Color ; , , , , .
Color
ImageIO.read, BufferedImage, getData Raster. .
ImageIO.read
BufferedImage
getData
Raster
rgb , .getData
.getData
:
Image img.getRGB(x, y); Color c = new Color(rgb);