Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.*;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- public class Gray extends JFrame {
- BufferedImage image;
- public Gray() throws IOException
- {
- File input = new File("v8.jpg");
- image = ImageIO.read(input);
- int h = image.getHeight();
- int w = image.getWidth();
- for (int i = 0; i < h; i++)
- {
- for (int j = 0; j < w; j++)
- {
- int pixel = image.getRGB(i, j);
- int alpha = (pixel >> 24) & 0xff;
- int red = (pixel >> 16) & 0xff;
- int green = (pixel >> 8) & 0xff;
- int blue = (pixel) & 0xff;
- int rgb=(red+green+blue)/3;
- image.setRGB(i, j, rgb);
- }
- }
- this.setTitle("Zaliczenie");
- this.setSize(500,500);
- this.setLocationRelativeTo(null);
- this.setResizable(true);
- }
- public void paint(Graphics g) {
- g.drawImage( image, 0, 0, null);
- }
- public static void main (String [] args) throws IOException
- {
- Gray progr = new Gray();
- progr.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment