當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。