I would like to know how i can change the HSL v开发者_运维技巧alues of a bitmap using C#. It must be possible to load a bitmap and change the HSL values of it on every pixel.
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
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.
精彩评论