本文整理汇总了C#中RGB类的典型用法代码示例。如果您正苦于以下问题:C# RGB类的具体用法?C# RGB怎么用?C# RGB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RGB类属于命名空间,在下文中一共展示了RGB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: isCompatible
/*
* Check whether the color of the object this script is attached to is
* compatible with the passed in color. Compatible colors are those that
* either match or match one of the component colors in the color wheel.
*/
public bool isCompatible(RGB theirRGB)
{
if (theirRGB.color == color) {
return true;
}
return false;
}
示例2: GetContrast
public static Color GetContrast(this Color Source, bool PreserveOpacity)
{
var inputColor = Source;
//if RGB values are close to each other by a diff less than 10%, then if RGB values are lighter side, decrease the blue by 50% (eventually it will increase in conversion below), if RBB values are on darker side, decrease yellow by about 50% (it will increase in conversion)
var avgColorValue = (byte) ((Source.R + Source.G + Source.B)/3);
var diff_r = Math.Abs(Source.R - avgColorValue);
var diff_g = Math.Abs(Source.G - avgColorValue);
var diff_b = Math.Abs(Source.B - avgColorValue);
if (diff_r < 20 && diff_g < 20 && diff_b < 20) //The color is a shade of gray
{
if (avgColorValue < 123) //color is dark
{
inputColor = Color.FromArgb(Source.A, 220, 230, 50);
}
else
{
inputColor = Color.FromArgb(Source.A, 255, 255, 50);
}
}
var sourceAlphaValue = Source.A;
if (!PreserveOpacity)
{
sourceAlphaValue = Math.Max(Source.A, (byte) 127); //We don't want contrast color to be more than 50% transparent ever.
}
var rgb = new RGB {R = inputColor.R, G = inputColor.G, B = inputColor.B};
var hsb = ConvertToHSB(rgb);
hsb.H = hsb.H < 180 ? hsb.H + 180 : hsb.H - 180;
//_hsb.B = _isColorDark ? 240 : 50; //Added to create dark on light, and light on dark
rgb = ConvertToRGB(hsb);
return Color.FromArgb(sourceAlphaValue, (int) rgb.R, (int) rgb.G, (int) rgb.B);
}
示例3: HSVtoColor
public static Color HSVtoColor(HSV hsv)
{
if (hsv == null)
return Color.Blue;
DRColor.RGB RGB = new RGB(hsv);
return Color.FromArgb(RGB.Red, RGB.Green, RGB.Blue);
}
示例4: GetRGB
public static RGB GetRGB(this Color self)
{
RGB rgb = new RGB();
rgb.r = self.r;
rgb.g = self.g;
rgb.b = self.b;
return rgb;
}
示例5: GetBufferFrames
public void GetBufferFrames()
{
FileBuffer.Seek(0, SeekOrigin.Begin);
BinaryFormatter mFormatter = new BinaryFormatter(FileBuffer);
FlcHeader.ReadData(mFormatter);
Civ3Header.ReadData(mFormatter);
SFliFrameHeader frameHeader = new SFliFrameHeader();
SFliChunkHeader chunkHeader = new SFliChunkHeader();
mBufferFrames = new byte[FlcHeader.frames + 8][];
mColourMap = new RGB[FlcHeader.frames + 8][];
for (short frame = 0; frame < FlcHeader.frames + 8; frame++) {
mBufferFrames[frame] = new byte[FlcHeader.width * FlcHeader.height];
mColourMap[frame] = new RGB[256];
if (frame > 0) {
Array.Copy(mBufferFrames[frame - 1], mBufferFrames[frame], sizeof(byte) * (FlcHeader.width * FlcHeader.height));
Array.Copy(mColourMap[frame - 1], mColourMap[frame], 256);
}
frameHeader.ReadData(mFormatter);
if (frameHeader.magic != 0xf1fa) {
//fseek(fp, frameHeader.Size - sizeof(frameHeader), SEEK_CUR);
ulong size = (ulong)System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFliFrameHeader));
mFormatter.ReadBytes((int)(frameHeader.size - size));
FlcHeader.frames--;
frame--;
continue;
}
for (int chunk = 0; chunk < frameHeader.chunks; chunk++) {
chunkHeader.ReadData(mFormatter);
switch (chunkHeader.type) {
case 4:
FlcColour256(mFormatter, frame);
break;
case 7:
long read = FlcDeltaFlc(mFormatter, frame);
mFormatter.ReadBytes((int)((long)chunkHeader.size - read));
break;
case 15:
FlcBitwiseRun(mFormatter, frame);
break;
default:
throw new NotImplementedException();
}
}
}
}
示例6: asRGB
/// <summary>
/// transformation HSV -> RGB
/// source: http://en.wikipedia.org/wiki/HSL_and_HSV (consistent with anything found on the web)
/// </summary>
/// <author>Birthe Anne Wiegand</author>
/// <returns>the RGB value</returns>
public RGB asRGB()
{
RGB temp = new RGB();
float f = this.H / 60f - (float)Math.Floor(this.H / 60f);
float p = this.V * (1f - this.S);
float q = this.V * (1f - this.S * f);
float t = this.V * (1f - this.S * (1 - f));
if (0f <= this.H && this.H < 60f)
{
temp.R = this.V;
temp.G = t;
temp.B = p;
}
else if (60f <= this.H && this.H < 120f)
{
temp.R = q;
temp.G = this.V;
temp.B = p;
}
else if (120f <= this.H && this.H < 180f)
{
temp.R = p;
temp.G = this.V;
temp.B = t;
}
else if (180f <= this.H && this.H < 240f)
{
temp.R = p;
temp.G = q;
temp.B = this.V;
}
else if (240f <= this.H && this.H < 300f)
{
temp.R = t;
temp.G = p;
temp.B = this.V;
}
else if (300f <= this.H && this.H < 360f)
{
temp.R = this.V;
temp.G = p;
temp.B = q;
}
else
{
System.Diagnostics.Debug.Write("HSV to RGB out of range");
}
return temp;
}
示例7: setPalette
public void setPalette(int colorCount, bool save = false)
{
unsafe
{
Clear();
for (int y = 0; y < Buffer.heightInPixels; y++)
{
byte* currentLine = Buffer.ptrFirstPixel + (y * Buffer.stride);
for (int x = 0; x < Buffer.widthInBytes; x = x + Buffer.bytesPerPixel)
{
colorList.Add(new RGB(Buffer.memoryStream[y, x + 2], Buffer.memoryStream[y, x + 1], Buffer.memoryStream[y, x]));
}
}
List<RGB> palette = GetPalette(colorCount);
int k = 0;
for (int y = 0; y < Buffer.heightInPixels; y++)
{
byte* currentLine = Buffer.ptrFirstPixel + (y * Buffer.stride);
for (int x = 0; x < Buffer.widthInBytes; x = x + Buffer.bytesPerPixel)
{
RGB color = new RGB(Buffer.memoryStream[y,x + 2], Buffer.memoryStream[y,x + 1], Buffer.memoryStream[y,x]);
Int32 b;
if (!cache.TryGetValue(color, out b))
{
for (int i = 0; i < cubeList.Count; i++)
{
if (cubeList[i].IsColorIn(color))
{
b = cubeList[i].PaletteIndex;
break;
}
}
}
currentLine[x + 2] = palette[b].R;
currentLine[x + 1] = palette[b].G;
currentLine[x] = palette[b].B;
}
}
if (save)
Buffer.addData();
Buffer.Refrash();
}
}
示例8: UnionTest
public void UnionTest()
{
// Byte is a value type, and will default to 0,
// so the default colour will be black!
var black = new RGB();
Assert.AreEqual(black.AsHex(), "000000");
var coral = new RGB(255, 125, 125);
Assert.AreEqual(coral.AsHex(), "FF7D7D");
var coralConverted = new RGB().FromHex("FF7D7D");
Assert.AreEqual(coralConverted.R, 255);
Assert.AreEqual(coralConverted.G, 125);
Assert.AreEqual(coralConverted.B, 125);
}
示例9: DoSwirlies
Pixel DoSwirlies(int x, int y)
{
var rgb = new RGB(0.0, 0.0, 0.0);
const double zoom = 0.5;
const int terms = 5;
_swirlies.ForEach(swirly =>
swirly.CalculateOnePoint(terms, _width, _height, zoom,
x, y, rgb));
return new Pixel(FloatToIntPixel(RemapColorRange(rgb.R)),
FloatToIntPixel(RemapColorRange(rgb.G)),
FloatToIntPixel(RemapColorRange(rgb.B)));
}
示例10: CombineColorChannels
public static byte[] CombineColorChannels(RGB[] rgb)
{
byte[] data = new byte[rgb.Length * 3];
int counter = 0;
for (int i = 0; i < data.Length; i += 3)
{
data[i] = rgb[counter].r;
data[i + 1] = rgb[counter].g;
data[i + 2] = rgb[counter].b;
++counter;
}
return data;
}
示例11: Load
protected override Image Load()
{
if (ReadHeader())
{
var colormap = new RGB[] {
new RGB(255,255,255),
new RGB(255,0,0),
new RGB(0,255,0),
new RGB(255,255,0),
new RGB(0,0,255),
new RGB(255,0,255),
new RGB(0,255,255),
new RGB(181,181,181),
new RGB(84,84,84),
new RGB(127,0,0),
new RGB(0,127,0),
new RGB(127,127,0),
new RGB(0,0,127),
new RGB(127,0,127),
new RGB(0,127,127),
new RGB(0,0,0)
};
var image = NewImage(_imageWidth, _imageHeight,
ImageBaseType.Indexed,
ImageType.Indexed, Filename);
image.Colormap = colormap;
var rgn = new PixelRgn(image.Layers[0], true, false);
int bparrow = (_imageWidth + 7) / 8;
for (int y = 0; y < _imageHeight; )
{
// byte[] line = new byte[bparrow * 8];
var line = new byte[_imageWidth];
int count = ReadLine(line);
do
{
rgn.SetRow(line, 0, y++);
}
while (--count > 0);
}
return image;
}
return null;
}
示例12: FxImages_32bppArgb
public FxImages_32bppArgb(Bitmap Image)
{
if (Image.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException("The input image must 32bppArgb");
}
// set the pilex format
FXPixelFormat = new RGB[4];
FXPixelFormat[0] = RGB.B;
FXPixelFormat[1] = RGB.G;
FXPixelFormat[2] = RGB.R;
FXPixelFormat[3] = RGB.A;
// set the internal image
localImage = Image;
}
示例13: ConvertToHSB
internal static HSB ConvertToHSB(RGB rgb)
{
// Following code is taken as it is from MSDN. See link below.
// By: <a href="http://blogs.msdn.com/b/codefx/archive/2012/02/09/create-a-color-picker-for-windows-phone.aspx" title="MSDN" target="_blank">Yi-Lun Luo</a>
var r = rgb.R;
var g = rgb.G;
var b = rgb.B;
var max = Max(r, g, b);
var min = Min(r, g, b);
var chroma = max - min;
var hue2 = 0d;
if (chroma != 0)
{
if (max == r)
{
hue2 = (g - b)/chroma;
}
else if (max == g)
{
hue2 = (b - r)/chroma + 2;
}
else
{
hue2 = (r - g)/chroma + 4;
}
}
var hue = hue2*60;
if (hue < 0)
{
hue += 360;
}
var brightness = max;
double saturation = 0;
if (chroma != 0)
{
saturation = chroma/brightness;
}
return new HSB
{
H = hue,
S = saturation,
B = brightness
};
}
示例14: Bilinear
/// <summary>
/// interpolate the input image in the specific position
/// and specific color, return byte
/// </summary>
/// <param name="image"></param>
/// <param name="xf"></param>
/// <param name="yf"></param>
/// <param name="color"></param>
/// <returns></returns>
public static byte Bilinear(FxImages image, float xf, float yf, RGB color)
{
if (yf + 1>= image.Image.Height)
yf = image.Image.Height - 2;
if (xf + 1 >= image.Image.Width)
xf = image.Image.Width - 2;
// get the integer part of the position
int x = (int)Math.Floor(xf);
int y = (int)Math.Floor(yf);
// get the ratio part
double x_ratio = xf - x;
double y_ratio = yf - y;
// the inverse ratio
double x_opposite = 1 - x_ratio;
double y_opposite = 1 - y_ratio;
byte result = 0;
// interpolate on x
if (y_opposite > 0)
{
if (x_opposite > 0)
result += (byte)(image[x, y, color] * x_opposite * y_opposite);
if (x_ratio > 0)
result += (byte)(image[x + 1, y, color] * x_ratio * y_opposite);
}
// interpolate on y
if (y_ratio > 0)
{
if (x_opposite > 0)
result += (byte)(image[x, y + 1, color] * x_opposite * y_ratio);
if (x_ratio > 0)
result += (byte)(image[x + 1, y + 1, color] * x_ratio * y_ratio);
}
return result;
}
示例15: GetMaterialForRGB
/*
* Gets the material that is associated with the specified RGB's color
*/
public static Material GetMaterialForRGB( RGB rgb)
{
Material returnMaterial = null;
switch (rgb.color) {
case ColorWheel.red:
returnMaterial = ColorManager.Instance.red;
break;
case ColorWheel.green:
returnMaterial = ColorManager.Instance.green;
break;
case ColorWheel.blue:
returnMaterial = ColorManager.Instance.blue;
break;
case ColorWheel.black:
returnMaterial = ColorManager.Instance.black;
break;
}
return returnMaterial;
}