abdulfatirs

HueChanger.java | Change hue of images

May 11th, 2014
1,442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. // @author Abdul Fatir
  2. import java.io.*;
  3. import javax.imageio.*;
  4. import java.awt.*;
  5. import java.awt.image.*;
  6. import static java.lang.System.out;
  7. public class HueChanger
  8. {
  9.     public static void main(String args[])throws IOException
  10.     {
  11.     BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.    
  13.     int iHUE=0;
  14.     do
  15.     {
  16.         out.print("Hue (0-360):");
  17.         iHUE = Integer.parseInt(reader.readLine());
  18.         if(iHUE > 360 || iHUE < 0)
  19.             {
  20.             out.println("Please enter a hue value between 0-360.");
  21.             }
  22.     }
  23.     while((iHUE > 360 || iHUE < 0));
  24.     float hue = iHUE/360.0f;
  25.    
  26.     BufferedImage raw,processed;
  27.     raw = ImageIO.read(new File("raw.png"));
  28.     int WIDTH = raw.getWidth();
  29.     int HEIGHT = raw.getHeight();
  30.     processed = new BufferedImage(WIDTH,HEIGHT,raw.getType());
  31.    
  32.     for(int Y=0; Y<HEIGHT;Y++)
  33.     {
  34.         for(int X=0;X<WIDTH;X++)
  35.         {
  36.             int RGB = raw.getRGB(X,Y);
  37.             int R = (RGB >> 16) & 0xff;
  38.             int G = (RGB >> 8) & 0xff;
  39.             int B = (RGB) & 0xff;
  40.             float HSV[]=new float[3];
  41.             Color.RGBtoHSB(R,G,B,HSV);
  42.             processed.setRGB(X,Y,Color.getHSBColor(hue,HSV[1],HSV[2]).getRGB());
  43.         }
  44.     }
  45.     ImageIO.write(processed,"PNG",new File("processed.png"));
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment