本文整理汇总了C#中RGB.To方法的典型用法代码示例。如果您正苦于以下问题:C# RGB.To方法的具体用法?C# RGB.To怎么用?C# RGB.To使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RGB
的用法示例。
在下文中一共展示了RGB.To方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <summary>
/// Processes the filter on the passed <paramref name="srcData"/>
/// resulting into <paramref name="dstData"/>.
/// </summary>
/// <param name="srcData">The source bitmap data.</param>
/// <param name="dstData">The destination bitmap data.</param>
protected override void Process(BitmapData srcData, BitmapData dstData)
{
int pixelSize = Image.GetPixelFormatSize(srcData.PixelFormat) / 8;
int w = srcData.Width;
int h = srcData.Height;
int offsetSrc = srcData.Stride - w * pixelSize;
int offsetDst = dstData.Stride - w;
// process image
unsafe
{
byte* src = (byte*)srcData.Scan0.ToPointer();
byte* dst = (byte*)dstData.Scan0.ToPointer();
// for each line
for (int y = 0; y < h; y++)
{
// for each pixel in line
for (int x = 0; x < w; x++, src += pixelSize, dst++)
{
RGB rgb = new RGB(src[RGBA.R], src[RGBA.G], src[RGBA.B]);
switch (ColorSpace)
{
case ColorSpaceEnum.HSB:
SetGrayscaleValue(dst, rgb.To<HSB>().Color, 359.764706, 1, 1);
break;
case ColorSpaceEnum.HSL:
SetGrayscaleValue(dst, rgb.To<HSL>().Color, 359.764706, 1, 1);
break;
case ColorSpaceEnum.LAB:
SetGrayscaleValue(dst, rgb.To<LAB>().Color, 100, 184.417028, 202.338137);
break;
case ColorSpaceEnum.LCH:
SetGrayscaleValue(dst, rgb.To<LCH>().Color, 100, 133.807615, 3.14159259);
break;
case ColorSpaceEnum.LUV:
SetGrayscaleValue(dst, rgb.To<LUV>().Color, 100, 258.092592, 241.501545);
break;
case ColorSpaceEnum.RGB:
SetGrayscaleValue(dst, rgb.Color, 255, 255, 255);
break;
case ColorSpaceEnum.SRGB:
SetGrayscaleValue(dst, rgb.To<SRGB>().Color, 1, 1, 1);
break;
case ColorSpaceEnum.XYZ:
SetGrayscaleValue(dst, rgb.To<XYZ>().Color, 0.95047, 1, 1.08883);
break;
}
}
src += offsetSrc;
dst += offsetDst;
}
}
}
示例2: Process
/// <summary>
/// Processes the filter on the passed <paramref name="srcData"/>
/// resulting into <paramref name="dstData"/>.
/// </summary>
/// <param name="srcData">The source bitmap data.</param>
/// <param name="dstData">The destination bitmap data.</param>
protected override void Process(BitmapData srcData, BitmapData dstData)
{
int pixelSize = Image.GetPixelFormatSize(srcData.PixelFormat) / 8;
int w = srcData.Width;
int h = srcData.Height;
int offset = srcData.Stride - w * pixelSize;
// process image
unsafe
{
byte* src = (byte*)srcData.Scan0.ToPointer();
// for each line
for (int y = 0; y < h; y++)
{
// Console.WriteLine(@"Process line {0}", y);
// for each pixel in line
for (int x = 0; x < w; x++, src += pixelSize)
{
RGB rgb = new RGB(src[RGBA.R], src[RGBA.G], src[RGBA.B]);
// HSB
IColorSpace cs = rgb.To<HSB>();
// max
double[] d = MaxValues[(int)ColorSpaceEnum.HSB];
d[0] = Math.Max(d[0], cs.Color.A);
d[1] = Math.Max(d[1], cs.Color.B);
d[2] = Math.Max(d[2], cs.Color.C);
MaxValues[(int)ColorSpaceEnum.HSB] = d;
// min
d = MinValues[(int)ColorSpaceEnum.HSB];
d[0] = Math.Min(d[0], cs.Color.A);
d[1] = Math.Min(d[1], cs.Color.B);
d[2] = Math.Min(d[2], cs.Color.C);
MinValues[(int)ColorSpaceEnum.HSB] = d;
// HSL
cs = rgb.To<HSL>();
// max
d = MaxValues[(int)ColorSpaceEnum.HSL];
d[0] = Math.Max(d[0], cs.Color.A);
d[1] = Math.Max(d[1], cs.Color.B);
d[2] = Math.Max(d[2], cs.Color.C);
MaxValues[(int)ColorSpaceEnum.HSL] = d;
// min
d = MinValues[(int)ColorSpaceEnum.HSL];
d[0] = Math.Min(d[0], cs.Color.A);
d[1] = Math.Min(d[1], cs.Color.B);
d[2] = Math.Min(d[2], cs.Color.C);
MinValues[(int)ColorSpaceEnum.HSL] = d;
// LAB
cs = rgb.To<LAB>();
// max
d = MaxValues[(int)ColorSpaceEnum.LAB];
d[0] = Math.Max(d[0], cs.Color.A);
d[1] = Math.Max(d[1], cs.Color.B);
d[2] = Math.Max(d[2], cs.Color.C);
MaxValues[(int)ColorSpaceEnum.LAB] = d;
// min
d = MinValues[(int)ColorSpaceEnum.LAB];
d[0] = Math.Min(d[0], cs.Color.A);
d[1] = Math.Min(d[1], cs.Color.B);
d[2] = Math.Min(d[2], cs.Color.C);
MinValues[(int)ColorSpaceEnum.LAB] = d;
// LCH
cs = rgb.To<LCH>();
// max
d = MaxValues[(int)ColorSpaceEnum.LCH];
d[0] = Math.Max(d[0], cs.Color.A);
d[1] = Math.Max(d[1], cs.Color.B);
if (!double.IsNaN(cs.Color.C))
{
d[2] = Math.Max(d[2], cs.Color.C);
}
MaxValues[(int)ColorSpaceEnum.LCH] = d;
// min
d = MinValues[(int)ColorSpaceEnum.LCH];
d[0] = Math.Min(d[0], cs.Color.A);
d[1] = Math.Min(d[1], cs.Color.B);
if (!double.IsNaN(cs.Color.C))
{
d[2] = Math.Min(d[2], cs.Color.C);
}
MinValues[(int)ColorSpaceEnum.LCH] = d;
// LUV
cs = rgb.To<LUV>();
// max
d = MaxValues[(int)ColorSpaceEnum.LUV];
d[0] = Math.Max(d[0], cs.Color.A);
d[1] = Math.Max(d[1], cs.Color.B);
d[2] = Math.Max(d[2], cs.Color.C);
MaxValues[(int)ColorSpaceEnum.LUV] = d;
//.........这里部分代码省略.........