Advertisement
abdulfatirs

HueChanger.java | Change hue of images

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