本文整理汇总了C#中Color.ToUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# Color.ToUInt32方法的具体用法?C# Color.ToUInt32怎么用?C# Color.ToUInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Color
的用法示例。
在下文中一共展示了Color.ToUInt32方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLine
public static void DrawLine(Viewport viewport, IBuffers buffers, int xstart, int ystart, int xend, int yend, Color color)
{
var colorAsInt = (int)color.ToUInt32();
var deltaX = xend - xstart;
var deltaY = yend - ystart;
var lengthX = deltaX >= 0 ? deltaX : -deltaX;
var lengthY = deltaY >= 0 ? deltaY : -deltaY;
var actualLength = lengthX > lengthY ? lengthX : lengthY;
if( actualLength != 0 )
{
var slopeX = (float) deltaX/(float) actualLength;
var slopeY = (float) deltaY/(float) actualLength;
var currentX = (float)xstart;
var currentY = (float)ystart;
for( var pixel=0; pixel<actualLength; pixel++)
{
if (currentX > 0 && currentY > 0 && currentX < viewport.Width && currentY < viewport.Height)
{
var bufferOffset = (buffers.FrameBuffer.Stride*(int) currentY) + (int) currentX;
buffers.FrameBuffer.Pixels[bufferOffset] = colorAsInt;
}
currentX += slopeX;
currentY += slopeY;
}
}
}
示例2: Draw
public void Draw(int x, int y, Color color, int size)
{
var framebuffer = BufferContainer.Framebuffer;
var frameBufferWidth = BufferContainer.Width;
var frameBufferHeight = BufferContainer.Height;
var colorAsInt = (int)color.ToUInt32();
for( var yIndex=y; yIndex<y+size; yIndex++ )
{
if (yIndex >= frameBufferHeight)
{
break;
}
if (yIndex < 0)
{
continue;
}
var yoffset = frameBufferWidth * yIndex;
for( var xIndex=x; xIndex<x+size; xIndex++)
{
if (xIndex >= frameBufferHeight)
{
break;
}
if (xIndex < 0)
{
continue;
}
var offset = yoffset + xIndex;
framebuffer[offset] = colorAsInt;
}
}
}
示例3: ConvertingToUInt32ShouldConvertAllComponentsCorrectly
public void ConvertingToUInt32ShouldConvertAllComponentsCorrectly()
{
var redColor = new Color { Red = 0xff };
var redResult = redColor.ToUInt32();
Assert.That(redResult, Is.EqualTo(0x00ff0000));
var greenColor = new Color { Green = 0xff };
var greenResult = greenColor.ToUInt32();
Assert.That(greenResult, Is.EqualTo(0x0000ff00));
var blueColor = new Color { Blue = 0xff };
var blueResult = blueColor.ToUInt32();
Assert.That(blueResult, Is.EqualTo(0x000000ff));
var alphaColor = new Color { Alpha = 0xff };
var alphaResult = alphaColor.ToUInt32();
Assert.That(alphaResult, Is.EqualTo(0xff000000));
var redAndAlphaColor = new Color { Red = 0xff, Alpha = 0xff };
var redAndAlphaResult = redAndAlphaColor.ToUInt32();
Assert.That(redAndAlphaResult, Is.EqualTo(0xffff0000));
var greenAndAlphaColor = new Color { Green = 0xff, Alpha = 0xff };
var greenAndAlphaResult = greenAndAlphaColor.ToUInt32();
Assert.That(greenAndAlphaResult, Is.EqualTo(0xff00ff00));
var redAndBlueColor = new Color { Red = 0xff, Blue = 0xff };
var redAndBlueResult = redAndBlueColor.ToUInt32();
Assert.That(redAndBlueResult, Is.EqualTo(0x00ff00ff));
}