How to take an image file and convert it to raster, and then access its data?

How to take an image file and convert it to a raster, and then access its data (RBG values) in pixels?

+5
source share
5 answers
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

+2
source
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 ; , , , , .

+2
+1

rgb , .getData

+1

:

Image img.getRGB(x, y);

Color c = new Color(rgb);
+1

All Articles