Change gradient image color from one color to another programatically in java

1

Currently in below code i am checking for each pixel if its white then if its not white then changing it to new color its not working for gradient image.specially shade on right and left corners.i have attached images blue one is input need to convert to another red image as output.Any suggestions will be helpful.

for (int xx = 0; xx < width; xx++) {
        for (int yy = 0; yy < height; yy++) {
            int clr = image.getRGB(xx, yy);
            int R = (clr & 0x00ff0000) >> 16;
            int G = (clr & 0x0000ff00) >> 8;
            int B = clr & 0x000000ff;
            double Y = 0.2126 * R + 0.7152 * G + 0.0722 * B;

            boolean isWhite = Y > 128 ? true : false;

            if (!isWhite) {
                int[] pixels = raster.getPixel(xx, yy, (int[]) null);
                pixels[0] = Integer.valueOf(hexColor.substring(1, 3), 16);
                pixels[1] = Integer.valueOf(hexColor.substring(3, 5), 16);
                pixels[2] = Integer.valueOf(hexColor.substring(5, 7), 16);
                raster.setPixel(xx, yy, pixels);
            }
        }
    }

Input Blue Image Output Red Image

java
image-processing
colors
gradient
asked on Stack Overflow Mar 20, 2019 by Joker

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0