当前位置: 首页>>代码示例>>C#>>正文


C# Color.ToUInt32方法代码示例

本文整理汇总了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;
                }
            }
        }
开发者ID:Conn,项目名称:Balder,代码行数:33,代码来源:Shapes.cs

示例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;
                }
            }
        }
开发者ID:petriw,项目名称:Balder,代码行数:35,代码来源:Point.cs

示例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));
 }
开发者ID:Conn,项目名称:Balder,代码行数:24,代码来源:ColorTests.cs


注:本文中的Color.ToUInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。