Advertisement
billysback

Y U NO LOAD FROM RESOURCES

Jul 17th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1.     public Image getImage(String url) {
  2.         try{
  3.             Image img = ImageIO.read(ImageManager.class.getResource(url));
  4.             return img;
  5.         }catch(Exception e) {
  6.            
  7.         }
  8.         return null;
  9.     }
  10.     public Image[] splitImage(Image image, int r, int c) {
  11.         BufferedImage img = (BufferedImage)image;
  12.         int rows = r;
  13.         int cols = c;  
  14.         int chunks = rows * cols;
  15.         int chunkWidth = img.getWidth() / cols;
  16.         int chunkHeight = img.getHeight() / rows;  
  17.         int count = 0;  
  18.         BufferedImage imgs[] = new BufferedImage[chunks];
  19.         for (int x = 0; x < rows; x++) {  
  20.             for (int y = 0; y < cols; y++) {  
  21.                 imgs[count] = new BufferedImage(chunkWidth, chunkHeight, img.getType());
  22.                 Graphics2D gr = imgs[count++].createGraphics();  
  23.                 gr.drawImage(img, 0, 0, chunkWidth, chunkHeight, chunkWidth * y, chunkHeight * x, chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, null);  
  24.                 gr.dispose();  
  25.             }  
  26.         }  
  27.         return imgs;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement