Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Image getImage(String url) {
- try{
- Image img = ImageIO.read(ImageManager.class.getResource(url));
- return img;
- }catch(Exception e) {
- }
- return null;
- }
- public Image[] splitImage(Image image, int r, int c) {
- BufferedImage img = (BufferedImage)image;
- int rows = r;
- int cols = c;
- int chunks = rows * cols;
- int chunkWidth = img.getWidth() / cols;
- int chunkHeight = img.getHeight() / rows;
- int count = 0;
- BufferedImage imgs[] = new BufferedImage[chunks];
- for (int x = 0; x < rows; x++) {
- for (int y = 0; y < cols; y++) {
- imgs[count] = new BufferedImage(chunkWidth, chunkHeight, img.getType());
- Graphics2D gr = imgs[count++].createGraphics();
- gr.drawImage(img, 0, 0, chunkWidth, chunkHeight, chunkWidth * y, chunkHeight * x, chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, null);
- gr.dispose();
- }
- }
- return imgs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement