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

  • SEARCH
  • Home
  • 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 390315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:57:09+00:00 2026-05-12T15:57:09+00:00

How do you convert an integer to a usable color (for PictureBox.CreateGraphics)? The color

  • 0

How do you convert an integer to a usable color (for PictureBox.CreateGraphics)?

The color should start at red, cycle to orange, yellow, etc. and come all the way back around to red again.

This is in vb.net. If I cannot do this, how do I use PictureBox.CreateGraphics with a hex code instead of a pen?

Thanks for the help!

  • 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-12T15:57:09+00:00Added an answer on May 12, 2026 at 3:57 pm

    You can use HSB (Hue, Saturation, Brightness) color instead of RGB color. .Net can convert RGB colors to HSB automatically (with the Color.GetHue, .GetSaturation and .GetBrightness methods) but doesn’t go in the other direction. Here is a code sample that handles converting HSB colors to RGB:

    http://splinter.com.au/blog/?p=29

    (this code sample uses “V” instead of “B”, probably for “value” instead of “brightness”).

    The advantage of using HSB color is that the Hue parameter ranges from 0 to 360, and can be interpreted as position on the color wheel, so the values wrap around nicely from 360 back to 0. For your purposes, you could create colors by setting the Saturation and Brightness values to 1.0 (their maximums) and then varying the Hue value to create the different colors of the spectrum.

    In regards to your specific question (and to elaborate on Rubens’ answer), you can create a Color from any int32 value like this:

    int i = 4837429;
    Color color = Color.FromArgb(i);
    

    However, this won’t achieve the wrap-around color effect that you describe in your question, and in fact much of the variation in your int32 values (assuming you range from the MinValue to the MaxValue) will apply to the alpha channel, or the opacity, which doesn’t sound like what you want.

    Update: here’s something that should do what you need:

    private const double ONE_SIXTH = 
        0.16666666666666666666666666666667;
    private const double ONE_THIRD = 
        0.33333333333333333333333333333333;
    private const double TWO_THIRDS = 
        0.66666666666666666666666666666667;
    private const double FIVE_SIXTHS = 
        0.83333333333333333333333333333333;
    public Color WheelColor(double d)
    {
        if ((d < 0.0) || (d > 1.0))
        {
            throw new ArgumentOutOfRangeException("d",
                d, "d must be between 0.0 and 1.0, inclusive");
        }
        double R = 1;
        double G = 1;
        double B = 1;
        if (d < ONE_SIXTH)
        {
            G = d / ONE_SIXTH;
            B = 0;
        }
        else if (d < ONE_THIRD)
        {
            R = 1 - ((d - ONE_SIXTH) / ONE_SIXTH);
            B = 0;
        }
        else if (d < 0.5)
        {
            R = 0;
            B = (d - ONE_THIRD) / ONE_SIXTH;
        }
        else if (d < TWO_THIRDS)
        {
            R = 0;
            G = 1 - ((d - 0.5) / ONE_SIXTH);
        }
        else if (d < FIVE_SIXTHS)
        {
            R = (d - TWO_THIRDS) / ONE_SIXTH;
            G = 0;
        }
        else
        {
            B = 1 - ((d - FIVE_SIXTHS) / ONE_SIXTH);
            G = 0;
        }
        return Color.FromArgb((int)(R * 255), 
            (int)(G * 255), (int)(B * 255));
    }
    

    The d parameter in WheelColor is meant to go from 0.0 to 1.0, and will cycle through the color wheel (sort of), starting at red when d = 0.0 and coming back to red when d = 1.0.

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

Sidebar

Related Questions

How do I convert integer byte values of red, green and blue to a
I'm trying to convert integer data to string , but I'm getting error cannot
Aim : To convert a integer value first to hexstring and then to byte[].
I need to convert an integer to it's ASCII representation from within the Linux
I need to convert an integer into a base64-character representation. I'm using OxA3's answer
I’m trying to convert each integer in a string to its corresponding value in
Is there a way to convert an integer to a string in PHP?
I am trying in javascript to convert an integer (which I know will be
is there a way in Java to convert an Integer to single digits, and
I was wondering what the easiest way is to convert an integer to the

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.