Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.awt.Color;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class Negatyw {
- private static BufferedImage image;
- // niepotrzebna tablica tablicy przy typie zmiennej
- private static int height;
- private static int width;
- public Negatyw(String s) { // ścieżka w argumencie
- try {
- File file = new File(s); // zmienna pomocnicza
- image = ImageIO.read(file);
- } catch (IOException ex) {
- System.err.println(ex.getLocalizedMessage());
- }
- width = image.getWidth()-1;
- height = image.getHeight()-1; // usuwamy printowanie
- }
- public static void main(String[] args) {
- Negatyw negativeImage = new Negatyw("../resources/Podział.jpg"); // lepsza nazwa obiektu
- // niepotrzebny label
- for (int i = 1; i < height; i++) {
- for (int j = 1; j < width; j++) {
- // niepotrzebny if
- int rgb = image.getRGB(i, j);
- Color color = new Color(rgb);
- // niepotrzebny if
- int red = color.getRed();
- int green = color.getGreen();
- int blue = color.getBlue();
- Color colorNegative = new Color(255-red, 255-green, 255-blue); // trzymamy się angielskich nazw zmiennych
- image.setRGB(i, j, colorNegative.getRGB());
- }
- }
- File newFile = new File("./Brudny.jpg");
- try {
- ImageIO.write(image, "jpg", newFile);
- } catch (IOException ex) {
- System.err.println(ex.getLocalizedMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement