Advertisement
Guest User

Untitled

a guest
May 9th, 2016
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.image.BufferedImage;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import javax.imageio.ImageIO;
  7.  
  8.  
  9.  
  10. public class Kep extends Component {
  11.  
  12.   public static void main(String[] foo) {
  13.       new Kep();
  14.   }
  15.  
  16.  
  17.   private void marchThroughImage(BufferedImage image) throws IOException {
  18.     int w = image.getWidth();
  19.     int h = image.getHeight();
  20.     BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  21.     System.out.println("width, height: " + w + ", " + h);
  22.  
  23.     for (int i = 0; i < h; i++) {
  24.       for (int j = 0; j < w; j++) {
  25.        
  26.         Color mycolor = new Color(image.getRGB(i, j));
  27.         int red = mycolor.getRed();
  28.         int green = mycolor.getGreen();
  29.         int blue = mycolor.getBlue();
  30.         int alpha = mycolor.getAlpha();
  31.        
  32.         int col = (alpha << 24) | (red << 16) | (green << 8) | blue;
  33.         img.setRGB(i, j, col);
  34.        
  35.       }
  36.     }
  37.    
  38.           File f = new File("MyFile.png");
  39.         ImageIO.write(img, "PNG", f);
  40.   }
  41.  
  42.  
  43.  
  44.   public Kep() {
  45.     try {
  46.       BufferedImage image =
  47.         ImageIO.read(this.getClass().getResource("asd.png"));
  48.       marchThroughImage(image);
  49.     } catch (IOException e) {
  50.       System.err.println(e.getMessage());
  51.     }
  52.   }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement