I would like to know how i can change the HSL values of a bitmap using C#. It must be possible to load a bitmap and change the HSL values of it on every pixel.
Asked
Active
Viewed 1,584 times
2 Answers
0
You'll have to look at the RGB of every pixel, convert it to HSL, modify the HSL values, convert back to RGB and write the new pixel data to the bitmap. Unfortunately, System.Drawing doesn't have a built in HSL to RGB functionality (although RGB to HSL does exist).
Check out the following code project article for a class that can do two way RGB/HSL conversions: http://www.codeproject.com/KB/recipes/colorspace1.aspx

viggity
- 15,039
- 7
- 88
- 96
0
You can use LockBits on your Bitmap, which will give you a BitmapData object.
With BitmapData you can:
- Use "unsafe" code blocks to iterate over every pixel and modify the value.
- Use Marshal.Copy to copy the pixels into an array, modify the values in the array, then copy it back to the bitmap source.
A detailed explanation of this topic can be found here.
Here is an article about RGB -> HSL which you might find useful.

Andrew Morton
- 24,203
- 9
- 60
- 84

Brandon Moretz
- 7,512
- 3
- 33
- 43