Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import javax.imageio.ImageIO;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.awt.Color;
- import static java.lang.System.out;
- public class SepiaNegativeToner
- {
- public static String ImageName="raw.png";
- public static void main(String args[])throws IOException
- {
- BufferedImage image,sepia,negative;
- image = ImageIO.read(new File(ImageName));
- int WIDTH = image.getWidth();
- int HEIGHT = image.getHeight();
- sepia = new BufferedImage(WIDTH,HEIGHT,image.getType());
- negative = new BufferedImage(WIDTH,HEIGHT,image.getType());
- // Looping through each pixel
- for(int y=0;y<HEIGHT;y++)
- {
- for(int x=0;x<WIDTH;x++)
- {
- int RGB = image.getRGB(x,y);
- int R = (RGB >> 16) & 0xff; // Red Value
- int G = (RGB >> 8) & 0xff; // Green Value
- int B = (RGB) & 0xff; // Blue Value
- // Output RGB values for Sepia
- int outputRed = (int)((R * .393) + (G *.769) + (B * .189));
- int outputGreen = (int)((R * .349) + (G *.686) + (B * .168));
- int outputBlue = (int)((R * .272) + (G *.534) + (B * .131));
- outputRed = Math.min(outputRed,255);
- outputGreen = Math.min(outputGreen,255);
- outputBlue = Math.min(outputBlue,255);
- sepia.setRGB(x,y, new Color(outputRed,outputGreen,outputBlue).getRGB());
- // Making the negative pixel
- Color complementary = new Color(255-R,255-G,255-B);
- negative.setRGB(x,y, complementary.getRGB());
- }
- }
- // Saving the Images
- ImageIO.write(sepia,"PNG",new File("sepia.png"));
- ImageIO.write(negative,"PNG",new File("negative.png"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement