Advertisement
SamKennedy

ImageHandler

Aug 19th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. public class ImageHandler {
  2.     public static int[][] loadImage(String imagePath) throws IOException{
  3.         BufferedImage img = ImageIO.read(new File(imagePath));
  4.         int[][] grid = new int[img.getWidth()][img.getHeight()];
  5.        
  6.         for(int x = 0; x < img.getWidth(); ++x){
  7.             for(int y = 0; y < img.getHeight(); ++y){
  8.                 int rgb = img.getRGB(x, y);
  9.                 grid[x][y] = (rgb) & 0x000000FF; //the height map is greyscale so
  10.                                                  //it doesn't matter which RGB component
  11.                                                  //is used
  12.             }
  13.         }
  14.        
  15.         return grid;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement