我正在尝试将HSB颜色转换为RGB.我这样做的方式是
System.Windows.Media.Color winColor = value;
System.Drawing.Color drawColor = System.Drawing.Color.FromArgb(winColor.R, winColor.G, winColor.B);
Hue = (byte)(drawColor.GetHue()*255);
Saturation = (byte)(drawColor.GetSaturation()*255);
Luminosity = (byte)(drawColor.GetBrightness()*255);
Run Code Online (Sandbox Code Playgroud)
我发现,当我有FF0000,它将被转换为H = 0, S = 255, L = 127转换为RGB FF0E0E.我觉得Luminosity应该是120?或者我是否让整个HSB错误?当我在Photoshop中查看颜色选择器时,Hue为0-360度,饱和度,亮度为0-100%.我的HSB值介于0到255之间,我做错了吗?
我目前有以下代码来查看位图的像素:
public struct Pixel
{
public byte Blue;
public byte Green;
public byte Red;
public byte Alpha;
public Pixel(byte blue, byte green, byte red, byte alpha)
{
Blue = blue;
Green = green;
Red = red;
Alpha = alpha;
}
}
public unsafe void Change(ref Bitmap inputBitmap)
{
Rectangle imageSize = new Rectangle(0, 0, inputBitmap.Width, inputBitmap.Height);
BitmapData imageData = inputBitmap.LockBits(imageSize, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
for (int indexY = 0; indexY < imageData.Height; indexY++)
{
byte* imageDataBytes = (byte*)imageData.Scan0 + (indexY * imageData.Stride); …Run Code Online (Sandbox Code Playgroud) 我有一个图像,我想将该特定图像的色调修改为特定值.我知道rgb到hsl和hsl到rgb的转换数学公式但是我无法将这个东西实现到c#中.
以下是伪:
for(x=0;x<image_width;x++)
{
for(y=0;y<image_height;y++)
{
Color oldColor=GetColorFromPixel(x,y);
Color newColor=ModifyHue(oldColor);
SetColorPixel(x,y,newColor);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢