Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:16
Show Gist options
  • Save ezhov-da/1f749ffbdac22128ee1207b0c5524fd6 to your computer and use it in GitHub Desktop.
Save ezhov-da/1f749ffbdac22128ee1207b0c5524fd6 to your computer and use it in GitHub Desktop.
java read image file
BufferedImage img = null;
try {
img = ImageIO. read(new File("Image. png") ) ;
int height = img. getHeight() ;
int width = img. getWidth() ;
int[] [] data = new int[height] [width] ;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j ++) {
int rgb = img. getRGB(i, j ) ; // negative integers
data[i] [j ] = rgb;
}
}
} catch (IOException e) {
// handle exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment