Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:29:12+00:00 2026-05-30T05:29:12+00:00

I have list of colors in HEX format (for example #000000) and I would

  • 0

I have list of colors in HEX format (for example #000000) and I would like to detect color type (blue, red, green etc.) and then change color type to another color type. Is this possible and are there any frameworks/libraries for this task?

Example:

I have color #EB1369 (red) then I convert it to blue and it becomes for example #1313EB (blue).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:29:13+00:00Added an answer on May 30, 2026 at 5:29 am

    Here’s a function that will let you shift colors around the hue circle. You should read the wikipedia page on the HSB (or HSV) color system to really understand what is going on: http://en.wikipedia.org/wiki/HSV_color_space

    /** Converts an input color given as a String such as "ab451e" to
     * the HSB color space. Shifts its hue from the given angle in degrees. 
     * Then returns the new color in the same format it was given.
     * 
     *  For example shift("ff0000", 180); returns "80ff00" (green is the opposite of red).*/
    public static String shift(String rgbS, int angle) {        
        // Convert String to integer value
        int value = Integer.parseInt(rgbS, 16);
    
        // Separate red green and blue
        int r = value >> 16;
        int g = (value >> 8) & 0xff;
        int b = value & 0xff;
    
        // Convert to hsb
        float[] hsb = Color.RGBtoHSB(r, g, b, null);
    
        // Convert angle to floating point between 0 and 1.0
        float angleF = (float)(angle/360.0);
    
        // Shift the hue using the angle.
        float newAngle = hsb[0] + angleF;
        if(newAngle > 1.0)
            newAngle = newAngle - 1.0f;
        hsb[0] = newAngle;
    
        // Convert back to RGB, removing the alpha component
        int rgb = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
        rgb = rgb & 0xffffff;
    
        // Build a new String
        return Integer.toHexString(rgb);
    }
    

    Detecting colors can be complex, it depends on the result you really expect.

    If what you want is simply an approximation (red, green, blue, yellow, etc.) then you can look at the hue circle of the HSB color-space, choose a hue value for each color you want to define, and then map the color you get in input to the closest one you chose.

    You can also rely on things like named HTML colors: http://www.w3schools.com/html/html_colornames.asp . Take this list, create a mapping in your program, then all you have to do is map the color you get to the closest one in your map, and return its name. Be wary though: computing the distance between two colors can be tricky (especially in RGB) and naive approaches (such as channel-by-channel difference) can give surprisingly bad results. Colorimetry is a complex topic, and you will find good methods on this page: http://en.wikipedia.org/wiki/Color_difference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably a very naive question: I have a list: color = [red,blue,red,green,blue] Now, I
I have a long list (1000+) of hex colors broken up in general color
I have a list of colors in HEX format: String[] validcolors = new String[]
I have a list like this: Red Red Brown Yellow Green Green Brown Red
I want to create a list of colors, red-yellow-green-blue, and blend into each other
I have a list of colors represented in hex - I need to sort
Let's say that I have a list of valid color values like [0x67FF82, 0x808080,
I have a list filled with colors used to color rectangles and i want
I have 3 MySQL tables: color id_color (1, 2, 3, 4) title ('blue', 'red',
I have several list of colors (TColor) stored in arrays which i like sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.