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 7701449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:59:18+00:00 2026-05-31T22:59:18+00:00

How can I replace a color for some parts of an image without affecting

  • 0

How can I replace a color for some parts of an image without affecting its texture?

You can see good example of the result in this screenshot

enter image description here

Source: https://www.leadtools.com/sdk/image-processing/functions/function.asp?id=158

  • 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-31T22:59:19+00:00Added an answer on May 31, 2026 at 10:59 pm

    Found the way to do it. This requires RGB<->HSL conversions (I used this class by Rich Newman for HSLColor:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    
    namespace ColorDemo
    {
       public class HSLColor
       {
           // Private data members below are on scale 0-1
           // They are scaled for use externally based on scale
           private double hue = 1.0;
           private double saturation = 1.0;
           private double luminosity = 1.0;
    
           private const double scale = 240.0;
    
           public double Hue
           {
               get { return hue * scale; }
               set { hue = CheckRange(value / scale); }
           }
           public double Saturation
           {
               get { return saturation * scale; }
               set { saturation = CheckRange(value / scale); }
           }
           public double Luminosity
           {
               get { return luminosity * scale; }
               set { luminosity = CheckRange(value / scale); }
           }
    
           private double CheckRange(double value)
           {
               if (value < 0.0)
                   value = 0.0;
               else if (value > 1.0)
                   value = 1.0;
               return value;
           }
    
           public override string ToString()
           {
               return String.Format("H: {0:#0.##} S: {1:#0.##} L: {2:#0.##}", Hue, Saturation, Luminosity);
           }
    
           public string ToRGBString()
           {
               Color color = (Color)this;
               return String.Format("R: {0:#0.##} G: {1:#0.##} B: {2:#0.##}", color.R, color.G, color.B);
           }
    
           #region Casts to/from System.Drawing.Color
           public static implicit operator Color(HSLColor hslColor)
           {
               double r = 0, g = 0, b = 0;
               if (hslColor.luminosity != 0)
               {
                   if (hslColor.saturation == 0)
                       r = g = b = hslColor.luminosity;
                   else
                   {
                       double temp2 = GetTemp2(hslColor);
                       double temp1 = 2.0 * hslColor.luminosity - temp2;
    
                       r = GetColorComponent(temp1, temp2, hslColor.hue + 1.0 / 3.0);
                       g = GetColorComponent(temp1, temp2, hslColor.hue);
                       b = GetColorComponent(temp1, temp2, hslColor.hue - 1.0 / 3.0);
                   }
               }
               return Color.FromArgb((int)(255 * r), (int)(255 * g), (int)(255 * b));
           }
    
           private static double GetColorComponent(double temp1, double temp2, double temp3)
           {
               temp3 = MoveIntoRange(temp3);
               if (temp3 < 1.0 / 6.0)
                   return temp1 + (temp2 - temp1) * 6.0 * temp3;
               else if (temp3 < 0.5)
                   return temp2;
               else if (temp3 < 2.0 / 3.0)
                   return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0);
               else
                   return temp1;
           }
           private static double MoveIntoRange(double temp3)
           {
               if (temp3 < 0.0)
                   temp3 += 1.0;
               else if (temp3 > 1.0)
                   temp3 -= 1.0;
               return temp3;
           }
           private static double GetTemp2(HSLColor hslColor)
           {
               double temp2;
               if (hslColor.luminosity < 0.5)  //<=??
                   temp2 = hslColor.luminosity * (1.0 + hslColor.saturation);
               else
                   temp2 = hslColor.luminosity + hslColor.saturation - (hslColor.luminosity * hslColor.saturation);
               return temp2;
           }
    
           public static implicit operator HSLColor(Color color)
           {
               HSLColor hslColor = new HSLColor();
               hslColor.hue = color.GetHue() / 360.0; // we store hue as 0-1 as opposed to 0-360 
               hslColor.luminosity = color.GetBrightness();
               hslColor.saturation = color.GetSaturation();
               return hslColor;
           }
           #endregion
    
           public void SetRGB(int red, int green, int blue)
           {
               HSLColor hslColor = (HSLColor)Color.FromArgb(red, green, blue);
               this.hue = hslColor.hue;
               this.saturation = hslColor.saturation;
               this.luminosity = hslColor.luminosity;
           }
    
           public HSLColor() { }
           public HSLColor(Color color)
           {
               SetRGB(color.R, color.G, color.B);
           }
           public HSLColor(int red, int green, int blue)
           {
               SetRGB(red, green, blue);
           }
           public HSLColor(double hue, double saturation, double luminosity)
           {
               this.Hue = hue;
               this.Saturation = saturation;
               this.Luminosity = luminosity;
           }
    
       }
    }
    
    1. Get a reference value (in hsl) representing the color you want to replace
    2. Get the hsl value for your target color
    3. Get image pixels and for each pixel:
    4. calculate the hsl value of the pixel, and replace it with (pixelHsl / refHsl) * targetHsl
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I have Stencil prepared with a texture (Image) in OpenGL 2.0 So that
so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim
I need to know how I can replace the last s from a string
Is there a built-in .NET class that can replace or work like WinHttp.WinHttpRequest? Thanks!
I'd like a regexp or other string which can replace everything except alphanumeric chars
Is it possible to develop a plug-in for Internet Explorer that can replace the
Can I replace the maxlength attribute with something in CSS? <input type='text' id=phone_extension maxlength=4
How can I replace lone instances of \n with \r\n (LF alone with CRLF)
How can I replace multiple spaces in a string with only one space in
How can I replace Line Breaks within a string in C#?

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.