本文整理汇总了C#中ColorRgba类的典型用法代码示例。如果您正苦于以下问题:C# ColorRgba类的具体用法?C# ColorRgba怎么用?C# ColorRgba使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColorRgba类属于命名空间,在下文中一共展示了ColorRgba类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static void Create(Vector3 pos, string text, ColorRgba color)
{
GameObject pe = new GameObject(GameRes.Data.Prefabs.PowerupEffect_Prefab);
pe.GetComponent<PowerupEffect>().Text = text;
pe.GetComponent<TextRenderer>().ColorTint = color;
pe.Transform.Pos = pos;
Scene.Current.RegisterObj(pe);
}
示例2: PixelData
public PixelData(int width, int height, ColorRgba[] data)
{
if (data == null) throw new ArgumentNullException("data");
if (width < 0) throw new ArgumentException("Width may not be negative.", "width");
if (height < 0) throw new ArgumentException("Height may not be negative.", "height");
this.SetPixelDataRgba(data, width, height);
}
示例3: PixelData
public PixelData(int width, int height, ColorRgba backColor)
{
if (width < 0) throw new ArgumentException("Width may not be negative.", "width");
if (height < 0) throw new ArgumentException("Height may not be negative.", "height");
this.width = width;
this.height = height;
this.data = new ColorRgba[width * height];
for (int i = 0; i < this.data.Length; i++)
this.data[i] = backColor;
}
示例4: GetPixelDataRgba
/// <summary>
/// Extracts a Bitmaps pixel data.
/// </summary>
/// <param name="bm"></param>
/// <returns></returns>
public static ColorRgba[] GetPixelDataRgba(this Bitmap bm)
{
int[] argbValues = GetPixelDataIntArgb(bm);
// Convert to ColorRGBA
ColorRgba[] result = new ColorRgba[argbValues.Length];
unchecked
{
for (int i = 0; i < argbValues.Length; i++)
result[i].SetIntArgb(argbValues[i]);
}
return result;
}
示例5: VisualizeAtlas
public static void VisualizeAtlas(Bitmap bitmap, List<Rect> atlas)
{
ColorRgba atlasColor = new ColorRgba(255, 128, 128, 164);
// Draw atlas rects
if (atlas != null)
{
Pen atlasPen = new Pen(Color.FromArgb(atlasColor.A, atlasColor.R, atlasColor.G, atlasColor.B));
using (Graphics g = Graphics.FromImage(bitmap))
{
foreach (Rect r in atlas) g.DrawRectangle(atlasPen, r.X, r.Y, r.W, r.H);
}
}
}
示例6: if
void ICmpUpdatable.OnUpdate()
{
Trigger trig = this.GameObj.GetComponent<Trigger>();
SpriteRenderer sprite = this.GameObj.GetComponent<SpriteRenderer>();
if (trig.Triggered && !this.wasTriggered)
{
this.oldColorTint = sprite.ColorTint;
sprite.ColorTint = ColorRgba.Mix(this.oldColorTint, ColorRgba.Red, 0.5f);
}
else if (!trig.Triggered && this.wasTriggered)
{
sprite.ColorTint = this.oldColorTint;
}
this.wasTriggered = trig.Triggered;
}
示例7: SetPixelDataArgb
public static void SetPixelDataArgb(this PixelData pixelData, int[] data, int width = -1, int height = -1)
{
if (width < 0) width = pixelData.Width;
if (height < 0) height = pixelData.Height;
if (data.Length != width * height) throw new ArgumentException("Data length doesn't match width * height", "pixelData");
ColorRgba[] tempData = new ColorRgba[width * height];
Parallel.ForEach(Partitioner.Create(0, tempData.Length), range =>
{
for (int i = range.Item1; i < range.Item2; i++)
{
tempData[i].A = (byte)((data[i] & 0xFF000000) >> 24);
tempData[i].R = (byte)((data[i] & 0x00FF0000) >> 16);
tempData[i].G = (byte)((data[i] & 0x0000FF00) >> 8);
tempData[i].B = (byte)((data[i] & 0x000000FF) >> 0);
}
});
pixelData.SetData(tempData, width, height);
}
示例8: Read
public PixelData Read(Stream stream)
{
ColorRgba[] rawColorData;
int width;
int height;
PixelData pixelData = new PixelData();
using (Bitmap bitmap = Bitmap.FromStream(stream) as Bitmap)
{
// Retrieve data
BitmapData bitmapData = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
int pixelCount = bitmapData.Width * bitmapData.Height;
int[] argbValues = new int[pixelCount];
Marshal.Copy(bitmapData.Scan0, argbValues, 0, pixelCount);
bitmap.UnlockBits(bitmapData);
width = bitmapData.Width;
height = bitmapData.Height;
rawColorData = new ColorRgba[width * height];
Parallel.ForEach(Partitioner.Create(0, rawColorData.Length), range =>
{
for (int i = range.Item1; i < range.Item2; i++)
{
rawColorData[i].A = (byte)((argbValues[i] & 0xFF000000) >> 24);
rawColorData[i].R = (byte)((argbValues[i] & 0x00FF0000) >> 16);
rawColorData[i].G = (byte)((argbValues[i] & 0x0000FF00) >> 8);
rawColorData[i].B = (byte)((argbValues[i] & 0x000000FF) >> 0);
}
});
}
pixelData.SetData(rawColorData, width, height);
pixelData.ColorTransparentPixels();
return pixelData;
}
示例9: ColorChangeElement
public ColorChangeElement(ColorRgba color)
{
this.color = color;
}
示例10: PrepareVertices
protected void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
{
Vector3 posTemp = this.gameobj.Transform.Pos;
float scaleTemp = 1.0f;
device.PreprocessCoords(ref posTemp, ref scaleTemp);
Vector2 xDot, yDot;
MathF.GetTransformDotVec(this.GameObj.Transform.Angle, scaleTemp, out xDot, out yDot);
Rect rectTemp = this.rect.Transformed(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
float left = uvRect.X;
float right = uvRect.RightX;
float top = uvRect.Y;
float bottom = uvRect.BottomY;
if ((this.flipMode & FlipMode.Horizontal) != FlipMode.None)
MathF.Swap(ref left, ref right);
if ((this.flipMode & FlipMode.Vertical) != FlipMode.None)
MathF.Swap(ref top, ref bottom);
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y;
vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[0].TexCoord.X = left;
vertices[0].TexCoord.Y = top;
vertices[0].Color = mainClr;
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y;
vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[1].TexCoord.X = left;
vertices[1].TexCoord.Y = bottom;
vertices[1].Color = mainClr;
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y;
vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[2].TexCoord.X = right;
vertices[2].TexCoord.Y = bottom;
vertices[2].Color = mainClr;
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y;
vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[3].TexCoord.X = right;
vertices[3].TexCoord.Y = top;
vertices[3].Color = mainClr;
if (this.pixelGrid)
{
vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
{
vertices[0].Pos.X += 0.5f;
vertices[1].Pos.X += 0.5f;
vertices[2].Pos.X += 0.5f;
vertices[3].Pos.X += 0.5f;
}
vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
{
vertices[0].Pos.Y += 0.5f;
vertices[1].Pos.Y += 0.5f;
vertices[2].Pos.Y += 0.5f;
vertices[3].Pos.Y += 0.5f;
}
}
}
示例11: DrawOnto
/// <summary>
/// Performs a drawing operation from this Layer to a target layer.
/// </summary>
/// <param name="target"></param>
/// <param name="blend"></param>
/// <param name="destX"></param>
/// <param name="destY"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="srcX"></param>
/// <param name="srcY"></param>
/// <param name="colorTint"></param>
public void DrawOnto(Layer target, BlendMode blend, int destX, int destY, int width, int height, int srcX, int srcY, ColorRgba colorTint)
{
if (colorTint == ColorRgba.White)
{
this.DrawOnto(target, blend, destX, destY, width, height, srcX, srcY);
return;
}
if (width == -1) width = this.width;
if (height == -1) height = this.height;
int beginX = MathF.Max(0, -destX, -srcX);
int beginY = MathF.Max(0, -destY, -srcY);
int endX = MathF.Min(width, this.width, target.width - destX, this.width - srcX);
int endY = MathF.Min(height, this.height, target.height - destY, this.height - srcY);
if (endX - beginX < 1) return;
if (endY - beginY < 1) return;
ColorRgba clrSource;
ColorRgba clrTarget;
System.Threading.Tasks.Parallel.For(beginX, endX, i =>
//for (int i = beginX; i < endX; i++)
{
for (int j = beginY; j < endY; j++)
{
int sourceN = srcX + i + this.width * (srcY + j);
int targetN = destX + i + target.width * (destY + j);
clrSource = this.data[sourceN] * colorTint;
if (blend == BlendMode.Solid)
{
target.data[targetN] = clrSource;
}
else if (blend == BlendMode.Mask)
{
if (clrSource.A >= 0) target.data[targetN] = this.data[sourceN];
}
else if (blend == BlendMode.Add)
{
clrTarget = target.data[targetN];
float alphaTemp = (float)clrSource.A / 255.0f;
target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.R + clrSource.R * alphaTemp)));
target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.G + clrSource.G * alphaTemp)));
target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.B + clrSource.B * alphaTemp)));
target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
}
else if (blend == BlendMode.Alpha)
{
clrTarget = target.data[targetN];
float alphaTemp = (float)clrSource.A / 255.0f;
target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.R * (1.0f - alphaTemp) + clrSource.R * alphaTemp)));
target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.G * (1.0f - alphaTemp) + clrSource.G * alphaTemp)));
target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.B * (1.0f - alphaTemp) + clrSource.B * alphaTemp)));
target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrTarget.A * (1.0f - alphaTemp) + clrSource.A)));
}
else if (blend == BlendMode.Multiply)
{
clrTarget = target.data[targetN];
float clrTempR = (float)clrTarget.R / 255.0f;
float clrTempG = (float)clrTarget.G / 255.0f;
float clrTempB = (float)clrTarget.B / 255.0f;
float clrTempA = (float)clrTarget.A / 255.0f;
target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.R * clrTempR)));
target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.G * clrTempG)));
target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.B * clrTempB)));
target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
}
else if (blend == BlendMode.Light)
{
clrTarget = target.data[targetN];
float clrTempR = (float)clrTarget.R / 255.0f;
float clrTempG = (float)clrTarget.G / 255.0f;
float clrTempB = (float)clrTarget.B / 255.0f;
float clrTempA = (float)clrTarget.A / 255.0f;
target.data[targetN].R = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.R * clrTempR + clrTarget.R)));
target.data[targetN].G = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.G * clrTempG + clrTarget.G)));
target.data[targetN].B = (byte)Math.Min(255, Math.Max(0, (int)Math.Round(clrSource.B * clrTempB + clrTarget.B)));
target.data[targetN].A = (byte)Math.Min(255, Math.Max(0, (int)clrTarget.A + (int)clrSource.A));
}
else if (blend == BlendMode.Invert)
{
clrTarget = target.data[targetN];
float clrTempR = (float)clrTarget.R / 255.0f;
float clrTempG = (float)clrTarget.G / 255.0f;
float clrTempB = (float)clrTarget.B / 255.0f;
float clrTempA = (float)clrTarget.A / 255.0f;
float clrTempR2 = (float)clrSource.R / 255.0f;
float clrTempG2 = (float)clrSource.G / 255.0f;
//.........这里部分代码省略.........
示例12: ColorTransparentPixels
/// <summary>
/// Sets the color of all transparent pixels to the specified color.
/// </summary>
/// <param name="transparentColor"></param>
public void ColorTransparentPixels(ColorRgba transparentColor)
{
for (int i = 0; i < this.data.Length; i++)
{
if (this.data[i].A != 0) continue;
this.data[i] = transparentColor;
}
}
示例13: CloneSubImage
/// <summary>
/// Extracts a rectangular region of this Layer. If the extracted region is bigger than the original Layer,
/// all new space is filled with a background color.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="w"></param>
/// <param name="h"></param>
/// <param name="backColor"></param>
public Layer CloneSubImage(int x, int y, int w, int h, ColorRgba backColor)
{
Layer tempLayer = new Layer(w, h, backColor);
this.DrawOnto(tempLayer, BlendMode.Solid, -x, -y);
return tempLayer;
}
示例14: InternalRescale
private ColorRgba[] InternalRescale(int w, int h, FilterMethod filter)
{
if (this.width == w && this.height == h) return null;
ColorRgba[] tempDestData = new ColorRgba[w * h];
if (filter == FilterMethod.Nearest)
{
// Don't use Parallel.For here, the overhead is too big and the compiler
// does a great job optimizing this piece of code without, so don't get in the way.
for (int i = 0; i < tempDestData.Length; i++)
{
int y = i / w;
int x = i - (y * w);
int xTmp = (x * this.width) / w;
int yTmp = (y * this.height) / h;
int nTmp = xTmp + (yTmp * this.width);
tempDestData[i] = this.data[nTmp];
}
}
else if (filter == FilterMethod.Linear)
{
//for (int i = 0; i < tempDestData.Length; i++)
System.Threading.Tasks.Parallel.For(0, tempDestData.Length, i =>
{
int y = i / w;
int x = i - (y * w);
float xRatio = ((float)(x * this.width) / (float)w) + 0.5f;
float yRatio = ((float)(y * this.height) / (float)h) + 0.5f;
int xTmp = (int)xRatio;
int yTmp = (int)yRatio;
xRatio -= xTmp;
yRatio -= yTmp;
int xTmp2 = xTmp + 1;
int yTmp2 = yTmp + 1;
xTmp = xTmp < this.width ? xTmp : this.width - 1;
yTmp = (yTmp < this.height ? yTmp : this.height - 1) * this.width;
xTmp2 = xTmp2 < this.width ? xTmp2 : this.width - 1;
yTmp2 = (yTmp2 < this.height ? yTmp2 : this.height - 1) * this.width;
int nTmp0 = xTmp + yTmp;
int nTmp1 = xTmp2 + yTmp;
int nTmp2 = xTmp + yTmp2;
int nTmp3 = xTmp2 + yTmp2;
tempDestData[i].R =
(byte)
(
((float)this.data[nTmp0].R * (1.0f - xRatio) * (1.0f - yRatio)) +
((float)this.data[nTmp1].R * xRatio * (1.0f - yRatio)) +
((float)this.data[nTmp2].R * yRatio * (1.0f - xRatio)) +
((float)this.data[nTmp3].R * xRatio * yRatio)
);
tempDestData[i].G =
(byte)
(
((float)this.data[nTmp0].G * (1.0f - xRatio) * (1.0f - yRatio)) +
((float)this.data[nTmp1].G * xRatio * (1.0f - yRatio)) +
((float)this.data[nTmp2].G * yRatio * (1.0f - xRatio)) +
((float)this.data[nTmp3].G * xRatio * yRatio)
);
tempDestData[i].B =
(byte)
(
((float)this.data[nTmp0].B * (1.0f - xRatio) * (1.0f - yRatio)) +
((float)this.data[nTmp1].B * xRatio * (1.0f - yRatio)) +
((float)this.data[nTmp2].B * yRatio * (1.0f - xRatio)) +
((float)this.data[nTmp3].B * xRatio * yRatio)
);
tempDestData[i].A =
(byte)
(
((float)this.data[nTmp0].A * (1.0f - xRatio) * (1.0f - yRatio)) +
((float)this.data[nTmp1].A * xRatio * (1.0f - yRatio)) +
((float)this.data[nTmp2].A * yRatio * (1.0f - xRatio)) +
((float)this.data[nTmp3].A * xRatio * yRatio)
);
});
}
return tempDestData;
}
示例15: EmitVertices
/// <summary>
/// Emits sets of vertices for glyphs and icons based on this formatted text. To render it, use each set of vertices combined with
/// the corresponding Fonts <see cref="Material"/>.
/// </summary>
/// <param name="vertText">One set of vertices for each Font that is available to this ForattedText.</param>
/// <param name="vertIcons">A set of icon vertices.</param>
/// <param name="x">An X-Offset applied to the position of each emitted vertex.</param>
/// <param name="y">An Y-Offset applied to the position of each emitted vertex.</param>
/// <param name="z">An Z-Offset applied to the position of each emitted vertex.</param>
/// <param name="clr">The color value that is applied to each emitted vertex.</param>
/// <param name="angle">An angle by which the text is rotated (before applying the offset).</param>
/// <param name="scale">A factor by which the text is scaled (before applying the offset).</param>
/// <returns>
/// Returns an array of vertex counts for each emitted vertex array.
/// Index 0 represents the number of emitted icon vertices, Index n represents the number of vertices emitted using Font n - 1.
/// </returns>
public int[] EmitVertices(ref VertexC1P3T2[][] vertText, ref VertexC1P3T2[] vertIcons, float x, float y, float z, ColorRgba clr, float angle = 0.0f, float scale = 1.0f)
{
Vector2 xDot, yDot;
MathF.GetTransformDotVec(angle, scale, out xDot, out yDot);
return this.EmitVertices(ref vertText, ref vertIcons, x, y, z, clr, xDot, yDot);
}