Java BufferedImage Operation hueShift(BufferedImage image, int hue)

Here you can find the source of hueShift(BufferedImage image, int hue)

Description

changes the hue of image.

License

Apache License

Parameter

Parameter Description
image base image
hue hue change 0-360

Return

a new hue-shifted image

Declaration

public static BufferedImage hueShift(BufferedImage image, int hue) 

Method Source Code


//package com.java2s;
/*    Copyright 2017 Ton Ly
     /*from  ww w .j a  v  a  2  s . com*/
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
     
  http://www.apache.org/licenses/LICENSE-2.0
     
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

import java.awt.*;
import java.awt.image.BufferedImage;

public class Main {
    /**
     * changes the hue of image. hue 0-360
     *
     * @param image base image
     * @param hue   hue change 0-360
     * @return a new hue-shifted image
     */
    public static BufferedImage hueShift(BufferedImage image, int hue) {
        BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
        float ihue = hue / 360.0f;
        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                int RGB = image.getRGB(x, y);
                int R = (RGB >> 16) & 0xff;
                int G = (RGB >> 8) & 0xff;
                int B = (RGB) & 0xff;
                float HSV[] = new float[3];
                Color.RGBtoHSB(R, G, B, HSV);
                result.setRGB(x, y, Color.getHSBColor(ihue, HSV[1], HSV[2]).getRGB());
            }
        }
        return result;
    }
}

Related

  1. greyScale(BufferedImage image)
  2. grid(BufferedImage image, int between)
  3. height(BufferedImage image, Double measurementLatitude, Double measurementLongitude)
  4. highlight(BufferedImage img, Color source, Color dest)
  5. hitTest(BufferedImage image, int x, int y)
  6. inColormap(float[][] in, float min, float max, float[][] colormap, BufferedImage b)
  7. indexToDirectColorModel(BufferedImage image)
  8. intBuffer2BufferedImage(IntBuffer ib, BufferedImage img)
  9. intensityArrayToBufferedImage(byte[] array, int w, int h)