Advertisement
mixster

mc_teo

Dec 24th, 2010
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. package mapMaker;
  2.  
  3. import java.awt.*;
  4. import java.awt.image.*;
  5. import java.io.*;
  6. import java.net.*;
  7.  
  8. import javax.imageio.*;
  9. import javax.swing.JApplet;
  10.  
  11.  
  12. public class Main extends JApplet {
  13. //  BufferedImage bground = loadImage("C:/Users/mc_teo/Desktop/pokemon_sprites.jpg");
  14.     BufferedImage bground = loadOnlineImage("http://www.freewebs.com/pokemontopazproject/pokemon%20sprites%201111112222233333444445555566666677777888889999900000.bmp");
  15.     BufferedImage db[];
  16.  
  17.     int tilew = 17;    // pixels per tile (including whitespace)
  18.     int tileh = 17;    // pixels per tile (including whitespace)
  19.     int realw = 16;    // pixels per tile (not including whitespace)
  20.     int realh = 16;    // pixels per tile (not including whitespace)
  21.    
  22.     public void prepim() {
  23.         int cols = bground.getWidth()/tilew;
  24.         int rows = bground.getHeight()/tileh;
  25.         int num = 0;
  26.         db = new BufferedImage[rows*cols];
  27.         for(int y = 0; y < rows; y++) {
  28.             for(int x = 0; x < cols; x++) {
  29.                 db[num] = new BufferedImage(realw, realh, bground.getType());
  30.                 // Tell the graphics to draw only one block of the image
  31.                 Graphics2D g = db[num].createGraphics();
  32. //              g.drawImage(bground, 0, 0, realw, realh, (tilew*x), (tileh*y), ((tilew*x)+realw), ((tileh*y)+realh), null);
  33.                 g.drawImage(bground, 0, 0, realw, realh, (tilew*x), (tileh*y), ((tilew*x)+realw), ((tileh*y)+realh), null);
  34.                 System.out.print("x: " + tilew*x + " y: " + tileh*y + " h: " + ((tileh*y)+realh) + " w: " + ((tilew*x)+realw) + '\n');
  35. //              System.out.print("");
  36.                 g.dispose();
  37.                 num++;
  38.             }
  39.         }
  40.     }
  41.    
  42.     public void init() {
  43.         setSize(bground.getWidth(), bground.getHeight());
  44.         prepim();
  45.     }  
  46.    
  47.     public void main() {
  48.         repaint();
  49.     }
  50.  
  51.     public void paint(Graphics g) {
  52.         int num = 0;
  53.         for(int y = 0; y < bground.getHeight()/tileh; y++){
  54.             for(int x = 0; x < bground.getWidth()/tilew; x++){
  55.                 g.drawImage(db[num], x*realh, y*realh, null);
  56. //              System.out.print("height: " + bground.getHeight() + " width: " + bground.getWidth() + '\n');
  57. //              System.out.print("x: " + x + " y: " + y + " x*y: " + (x*y) + '\n');
  58.                 num++;
  59.             }
  60.         }
  61.     }
  62.    
  63.     public static BufferedImage loadImage(String ref) {  
  64.         BufferedImage bimg = null;  
  65.         try {
  66.             bimg = ImageIO.read(new File(ref));  
  67.         } catch (Exception e) {  
  68.             e.printStackTrace();  
  69.         }  
  70.         return bimg;  
  71.     }
  72.  
  73.     public static BufferedImage loadOnlineImage(String ref) {  
  74.         BufferedImage bimg = null;  
  75.         try {
  76.             bimg = ImageIO.read(new URL(ref));
  77.         } catch (Exception e) {  
  78.             e.printStackTrace();  
  79.         }  
  80.         return bimg;  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement