Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 19th, 2012  |  syntax: Java  |  size: 2.68 KB  |  views: 35  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class DisplayImage extends JFrame {
  2.    
  3.   public DisplayImage(boolean resize, boolean mapCountries) throws IOException {
  4.     super("Province Map");
  5.     File mapProvinceFile = new File("map\\provinces.bmp");
  6.     BufferedImage mapProvinceImage = ImageIO.read(mapProvinceFile);
  7.    
  8.     byte[] pixels = (byte[])mapProvinceImage.getRaster().getDataElements(0, 0, mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), null);
  9.  
  10.     if (mapCountries) {
  11.         for (int i = 0; i < Victoria2Stats.provinceDefinitionArray.size(); i++) {
  12.             for (int p = 0; p < pixels.length-3; p = p + 3) {
  13.                if ((byte)Victoria2Stats.provinceDefinitionArray.get(i).rgb[0] == pixels[p]) {
  14.                    if ((byte)Victoria2Stats.provinceDefinitionArray.get(i).rgb[1] == pixels[p+1]) {
  15.                        if ((byte)Victoria2Stats.provinceDefinitionArray.get(i).rgb[2] == pixels[p+2]) {
  16.                            try {
  17.                                if ((Victoria2Stats.provinceDataTable[i].ownerColor == null) && !(Victoria2Stats.provinceDataTable[i].lifeRating == 0)) {
  18.                                     pixels[p] = (byte)255;
  19.                                     pixels[p+1] = (byte)255;
  20.                                     pixels[p+2] = (byte)255;
  21.                                } else {
  22.                                     pixels[p] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getRed());
  23.                                     pixels[p+1] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getBlue());
  24.                                     pixels[p+2] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getGreen());
  25.                                }
  26.                            } catch (NullPointerException e) {
  27.                                System.out.println("Null Problem: " + i);
  28.                            }
  29.                        }
  30.                    }
  31.                }
  32.           }
  33.       }
  34.     }
  35.    
  36.     BufferedImage buffer = new BufferedImage(mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), mapProvinceImage.getType());
  37.     DataBuffer dataBuffer = new DataBufferByte(pixels, pixels.length);
  38.    
  39.     SampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE, mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), 3, mapProvinceImage.getWidth()*3, new int[]{0,1,2});
  40.     Raster raster = Raster.createRaster(sampleModel, dataBuffer, null);
  41.     buffer.setData(raster);
  42.    
  43.     BufferedImage fixedImage = ImageUtils.verticalflip(buffer);
  44.     ImageIcon ii = new ImageIcon(fixedImage);
  45.     JScrollPane jsp = new JScrollPane(new JLabel(ii));
  46.     getContentPane().add(jsp);
  47.     setSize(800, 600);
  48.     setVisible(true);
  49.   }
  50.  
  51. }