Advertisement
Guest User

MapImage.java

a guest
Feb 9th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.image.BufferedImage;
  3. import org.bukkit.map.MapCanvas;
  4.  
  5. /**
  6.  *
  7.  * @author ECB2 (ECB2.biz)
  8.  *
  9.  */
  10.  
  11. public class MapImage {
  12.  
  13. private byte tag[];
  14.    
  15.     public MapImage(byte tag[])
  16.     {
  17.         this.tag = tag;
  18.     }
  19.    
  20.     public MapImage(BufferedImage image)
  21.     {
  22.         this.tag = this.convertImage(image);
  23.     }
  24.    
  25.     public byte getColor(int x, int y)
  26.     {
  27.         return tag[x + y * 128];
  28.     }
  29.    
  30.     public void draw(MapCanvas canvas)
  31.     {
  32.         for(int x = 0; x < 128; x++)
  33.         {
  34.             for(int y = 0; y < 128; y++)
  35.             {
  36.                 canvas.setPixel(x, y, this.getColor(x, y));
  37.             }
  38.         }
  39.     }
  40.    
  41.     private byte[] convertImage(BufferedImage bi)
  42.     {
  43.         byte[] colorsArray = new byte[128*128];
  44.         try{
  45.             for(int x = 0; x < 128; x++)
  46.             {
  47.                 for(int y = 0; y < 128; y++){
  48.                     byte c = (byte)ColorUtil.findId(new Color(bi.getRGB(x, y)));
  49.                     if(c==0||c==1||c==2||c==3) c = (byte)119;
  50.                     colorsArray[x + y * 128] = c;
  51.                 }
  52.             }
  53.         }catch(Exception ex){
  54.             ex.printStackTrace();
  55.         }
  56.         return colorsArray;
  57.     }
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement