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: 3.06 KB  |  views: 58  |  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 DisplayImage(boolean resize, boolean mapCountries) throws IOException {
  2.     super("Province Map");
  3.     File mapProvinceFile = new File("map\\provinces.bmp");
  4.     BufferedImage mapProvinceImage = ImageIO.read(mapProvinceFile);
  5.     File g = new File("unchanged.bmp");
  6.     ImageIO.write(mapProvinceImage, "bmp", g);
  7.     System.out.println("Image Type: " + mapProvinceImage.getType());
  8.    
  9.     byte[] pixels = (byte[])mapProvinceImage.getData().getDataElements(0, 0, mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), null);
  10.  
  11.     int check1 = 0;
  12.     int check2 = 0;
  13.     int check3 = 0;
  14.     int check4 = 0;
  15.     long pixelTotalValue = 0;
  16.     for (int i = 0; i < 150; i++) {
  17.         for (int p = 0; p < pixels.length; p = p + 3) {
  18.             if (mapCountries) {
  19.                if (Victoria2Stats.provinceDefinitionArray.get(i).red == pixels[p]) {
  20.                    check2++;
  21.                    if (Victoria2Stats.provinceDefinitionArray.get(i).green == pixels[p+1]) {
  22.                        check3++;
  23.                        if (Victoria2Stats.provinceDefinitionArray.get(i).blue == pixels[p+2]) {
  24.                            pixels[p] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getRed());
  25.                            pixels[p+1] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getGreen());
  26.                            pixels[p+2] = (byte)(Victoria2Stats.provinceDataTable[i].ownerColor.getBlue());
  27.                            check4++;
  28.                        }
  29.                    }
  30.                }
  31.             }
  32.                         pixelTotalValue = pixelTotalValue + pixels[p];
  33.                         pixelTotalValue = pixelTotalValue + pixels[p+1];
  34.                         pixelTotalValue = pixelTotalValue + pixels[p+2];
  35.         }
  36.     }
  37.        
  38.         System.out.println("Check 2: " + check2);
  39.         System.out.println("Check 3: " + check3);
  40.         System.out.println("Check 4: " + check4);
  41.    
  42.     System.out.println("Pixel Total Value: " + pixelTotalValue);
  43.    
  44.         for (int p = 0; p < 2000; p++) {
  45.                 //System.out.println("Pixel Value: " + pixels[p]);
  46.         }  
  47.                        
  48.     BufferedImage buffer = new BufferedImage(mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), mapProvinceImage.getType());
  49.     DataBuffer dataBuffer = new DataBufferByte(pixels.length, 1);
  50.     long bufferValue = 0;
  51.     for (int v = 0; v < pixels.length; v++) {
  52.         dataBuffer.setElem(v, pixels[v]);
  53.         bufferValue = bufferValue + pixels[v];
  54.     }
  55.     System.out.println("Buffer Value: " + bufferValue);
  56.        
  57.     SampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE, mapProvinceImage.getWidth(), mapProvinceImage.getHeight(), 3, mapProvinceImage.getWidth()*3, new int[]{0,1,2});
  58.         Raster raster = Raster.createRaster(sampleModel, dataBuffer, null);
  59.     buffer.setData(raster);
  60.    
  61.         File f = new File("newFile.bmp");
  62.     mapProvinceImage = ImageUtils.verticalflip(buffer);
  63.     ImageIO.write(mapProvinceImage, "bmp", f);
  64.     ImageIcon ii = new ImageIcon(mapProvinceImage);
  65.     JScrollPane jsp = new JScrollPane(new JLabel(ii));
  66.     getContentPane().add(jsp);
  67.     setSize(800, 600);
  68.     setVisible(true);
  69.   }