Guest User

Untitled

a guest
Jan 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.image.BufferedImage;
  3. import java.io.*;
  4.  
  5. import javax.imageio.ImageIO;
  6. import javax.swing.*;
  7.  
  8. public class Gray extends JFrame {
  9.  
  10. BufferedImage image;
  11.  
  12.  
  13.  
  14. public Gray() throws IOException
  15. {
  16. File input = new File("v8.jpg");
  17. image = ImageIO.read(input);
  18.  
  19. int h = image.getHeight();
  20. int w = image.getWidth();
  21.  
  22. for (int i = 0; i < h; i++)
  23. {
  24. for (int j = 0; j < w; j++)
  25. {
  26. int pixel = image.getRGB(i, j);
  27.  
  28.  
  29. int alpha = (pixel >> 24) & 0xff;
  30. int red = (pixel >> 16) & 0xff;
  31. int green = (pixel >> 8) & 0xff;
  32. int blue = (pixel) & 0xff;
  33. int rgb=(red+green+blue)/3;
  34.  
  35. image.setRGB(i, j, rgb);
  36.  
  37. }
  38. }
  39.  
  40. this.setTitle("Zaliczenie");
  41. this.setSize(500,500);
  42. this.setLocationRelativeTo(null);
  43. this.setResizable(true);
  44. }
  45.  
  46. public void paint(Graphics g) {
  47. g.drawImage( image, 0, 0, null);
  48. }
  49.  
  50. public static void main (String [] args) throws IOException
  51. {
  52. Gray progr = new Gray();
  53. progr.setVisible(true);
  54. }
  55.  
  56. }
Add Comment
Please, Sign In to add comment