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


C# Canvas.GetColor方法代码示例

本文整理汇总了C#中Canvas.GetColor方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.GetColor方法的具体用法?C# Canvas.GetColor怎么用?C# Canvas.GetColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canvas的用法示例。


在下文中一共展示了Canvas.GetColor方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Canvas_GetColor

        public void Test_Canvas_GetColor()
        {
            Canvas canvas = new Canvas(4, 2);
            canvas.Color[0, 3] = Color.Black;

            Assert.AreEqual(Color.Black, canvas.GetColor(3, 0));
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:7,代码来源:UnitCanvas.cs

示例2: ConvertCanvasToBitmap

        public Bitmap ConvertCanvasToBitmap(Canvas canvas)
        {
            if (canvas == null) throw new NullReferenceException("'canvas' can't be null");

            int width = canvas.Width;
            int height = canvas.Height;

            Bitmap image = new Bitmap(width, height);

            LockBitmap lockBitmap = new LockBitmap(image);
            lockBitmap.LockBits();

            Parallel.ForEach(Partitioner.Create(0, height), rangeHeight =>
                {
                    for(int y = rangeHeight.Item1; y < rangeHeight.Item2; y++)
                         for (int x = 0; x < width; x++)
                             lockBitmap.SetPixel(x, y, canvas.GetColor(x, y));
                });

            lockBitmap.UnlockBits();

            #region Obsolete
            /*
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                    image.SetPixel(x, y, canvas.GetColor(x, y));
            }
            */
            #endregion

            return image;
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:33,代码来源:CanvasConverter.cs

示例3: Test_CellsDecorator

        public void Test_CellsDecorator()
        {
            Settings settings = new Settings();
            settings.CellsCount = 3;
            settings.Coefficient = 2;
            settings.Palette = new Palette(new Color[] { Color.Red, Color.Green, Color.Blue });

            Canvas pattern = new Canvas(new Resolution(3, 2));
            #region FillingPattern
             for (int y = 0; y < 2; y++)
                for (int x = 0; x < 3; x++)
                {
                    if (x == 2 && y == 0)
                        pattern.SetColor(x, y, Color.Green);
                    else if (x == 1 && y == 1)
                       pattern.SetColor(x, y, Color.Blue);
                    else
                        pattern.SetColor(x, y, Color.Red);
                }
            #endregion

            Canvas expectedCanvas = new Canvas(new Resolution(6, 4));
            #region FillingFillingExpectedCanvas
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 6; x++)
                {
                    if ((x == 4 && y == 0) ||
                        (x == 5 && y == 0) ||
                        (x == 4 && y == 1) ||
                        (x == 5 && y == 1)
                        )
                        expectedCanvas.SetColor(x, y, Color.Green);
                    else if ((x == 2 && y == 2) ||
                            (x == 3 && y == 2) ||
                            (x == 2 && y == 3) ||
                            (x == 3 && y == 3)
                            )
                        expectedCanvas.SetColor(x, y, Color.Blue);
                    else
                        expectedCanvas.SetColor(x, y, Color.Red);
                }
            #endregion

            Canvas actual = new Canvas(new Resolution(6, 4));

            CellsDecorator decorator = new CellsDecorator();
            decorator.Decorate(actual, pattern, settings);

            Assert.IsTrue(actual.Height == expectedCanvas.Height && actual.Width == expectedCanvas.Width);

            for (int y = 0; y < expectedCanvas.Height; y++)
                for (int x = 0; x < expectedCanvas.Width; x++)
                    Assert.IsTrue(actual.GetColor(x, y) == expectedCanvas.GetColor(x, y));
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:54,代码来源:UnitDecorators.cs

示例4: Test_CanvasConverter_ConvertBitmapToCanvas

        public void Test_CanvasConverter_ConvertBitmapToCanvas()
        {
            Bitmap inputImage = new Bitmap(6, 4);
            #region Filling input image
            for(int y = 0; y < 4; y++)
                for (int x = 0; x < 6; x++)
                {
                    if ((x == 0 && y == 0) ||
                        (x == 5 && y == 1))
                        inputImage.SetPixel(x, y, Color.White);
                    else if ((x == 1 && y == 1) ||
                            (x == 5 && y == 3))
                        inputImage.SetPixel(x, y, Color.Blue);
                    else if ((x == 3 && y == 1) ||
                            (x == 2 && y == 2))
                        inputImage.SetPixel(x, y, Color.Green);
                    else inputImage.SetPixel(x, y, Color.Black);
                }
            #endregion

            Canvas expectedCanvas = new Canvas(6, 4);
            #region Filling expected canvas
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 6; x++)
                {
                    if ((x == 0 && y == 0) ||
                        (x == 5 && y == 1))
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 255, 255, 255));
                    else if ((x == 1 && y == 1) ||
                            (x == 5 && y == 3))
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 0, 0, 255));
                    else if ((x == 3 && y == 1) ||
                            (x == 2 && y == 2))
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 0, 128, 0));
                    else expectedCanvas.SetColor(x, y, Color.FromArgb(255, 0, 0, 0));
                }
            #endregion

            CanvasConverter converter = new CanvasConverter();
            Canvas actual = converter.ConvertBitmapToCanvas(inputImage);

            Assert.IsTrue(expectedCanvas.Width == actual.Width);
            Assert.IsTrue(expectedCanvas.Height == actual.Height);

            for (int y = 0; y < expectedCanvas.Height; y++)
                for (int x = 0; x < expectedCanvas.Width; x++)
                    Assert.AreEqual(expectedCanvas.GetColor(x, y), actual.GetColor(x, y));
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:48,代码来源:UnitCanvasConverter.cs

示例5: Decorate

        public void Decorate(Canvas embroidery, Canvas pattern, Settings settings)
        {
            log.Source = "EmbroiderySource";

            int squareWidth = embroidery.Width / settings.CellsCount;
            if (embroidery.Height < pattern.Height * squareWidth)
                throw new WrongResolutionException("Resolution.Height has to be higher");

            try
            {
                settings.CreateColorSymbolRelation();
            }
            catch (WrongSymbolsRealisationException e)
            {
                throw new WrongSymbolsRealisationException(e.Message);
            }
            catch (NullReferenceException e)
            {
                throw new NullReferenceException(e.Message);
            }

            Color symbolColor;
            if(settings.SymbolColor == Color.Empty) symbolColor = Color.Black;
            else symbolColor = settings.SymbolColor;

            Parallel.ForEach(Partitioner.Create(0, pattern.Height), rangeHeight =>
                {
                    for (int patternY = rangeHeight.Item1; patternY < rangeHeight.Item2; patternY++)
                    {
                        Parallel.ForEach(Partitioner.Create(0, pattern.Width), rangeWidth =>
                            {
                                for (int patternX = rangeWidth.Item1; patternX < rangeWidth.Item2; patternX++)
                                {
                                    int startX = patternX * squareWidth;
                                    int startY = patternY * squareWidth;

                                    char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
                                    embroidery.SetSymbol(symbol, startX, startY, squareWidth, symbolColor);
                                }
                            });
                    }
                });

            #region Just Parallel.For
            /*
            Parallel.For(0, pattern.Height, patternY =>
                {
                    Parallel.For(0, pattern.Width, patternX =>

                    {
                        int startX = patternX * squareWidth;
                        int startY = patternY * squareWidth;

                        char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
                        embroidery.SetSymbol(symbol, startX, startY, squareWidth, symbolColor);
                    });
                });
            */
            #endregion

            #region Obsolete
            /*for(int squareY = 0, patternY = 0; squareY <= embroidery.Height - squareWidth; squareY += squareWidth, patternY++)
                for (int squareX = 0, patternX = 0; squareX <= embroidery.Width - squareWidth; squareX += squareWidth, patternX++)
                {
                    char symbol = GetSymbol(pattern.GetColor(patternX, patternY), settings);
                    embroidery.SetSymbol(symbol, squareX, squareY, squareWidth, symbolColor);
                }*/
            #endregion
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:69,代码来源:SymbolsDecorator.cs

示例6: Test_Canvas_GetEnumerator

        public void Test_Canvas_GetEnumerator()
        {
            Canvas canvas = new Canvas(new Resolution(4, 3));
            #region Filling canvas
            for (int y = 0; y < 3; y++)
                for (int x = 0; x < 4; x++)
                {
                    if (x == 1 && y == 1) canvas.SetColor(x, y, Color.Red);
                    else if (x == 2 && y == 0) canvas.SetColor(x, y, Color.White);
                    else canvas.SetColor(x, y, Color.Black);
                }
            #endregion

            Color[] actualColors = new Color[4 * 3];

            int i = 0;
            foreach (Color color in canvas)
                actualColors[i++] = color;

            i = 0;
            for (int y = 0; y < 3; y++)
                for (int x = 0; x < 4; x++)
                    Assert.IsTrue(actualColors[i++] == canvas.GetColor(x, y));
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:24,代码来源:UnitCanvas.cs

示例7: Test_Canvas_SetSymbol

        public void Test_Canvas_SetSymbol()
        {
            Bitmap temp = new Bitmap(4, 4);

            Graphics g = Graphics.FromImage(temp);

            Font font = new Font("Arial", 4 - 1, GraphicsUnit.Pixel);
            string sym = "#";
            sym = sym.PadLeft(1, '#');

            SolidBrush brush = new SolidBrush(Color.Black);

            g.DrawString(sym, font, brush, new PointF(0f, 0f));

            CanvasConverter converter = new CanvasConverter();
            Canvas expectedCanvas = converter.ConvertBitmapToCanvas(temp);

            Canvas canvas = new Canvas(4, 4);
            canvas.SetSymbol('#', 0, 0, 4, Color.Black);

            Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height);

            for (int y = 0; y < canvas.Height; y++)
                for (int x = 0; x < canvas.Width; x++)
                {
                    Color actualColor = canvas.GetColor(x, y);
                    Color expectedColor = expectedCanvas.GetColor(x, y);
                    Assert.IsTrue(actualColor == expectedColor);
                }
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:30,代码来源:UnitCanvas.cs

示例8: Test_Canvas_SetInnerCanvas

        public void Test_Canvas_SetInnerCanvas()
        {
            Canvas canvas = new Canvas(new Resolution(10, 8));
            #region Filling canvas
            for (int y = 0; y < 8; y++)
                for (int x = 0; x < 10; x++)
                    canvas.SetColor(x, y, Color.Black);
            #endregion

            Canvas expected = new Canvas(new Resolution(10, 8));
            #region Filling expected canvas
            for (int y = 0; y < 8; y++)
                for (int x = 0; x < 10; x++)
                {
                    if (x == 5 && y == 2) expected.SetColor(x, y, Color.Red);
                    else if (x == 8 && y == 4) expected.SetColor(x, y, Color.Green);
                    else expected.SetColor(x, y, Color.Black);
                }
            #endregion

            Canvas inputCanvas = new Canvas(new Resolution(4, 3));
            #region Filling input canvas
            for (int y = 0; y < 3; y++)
                for (int x = 0; x < 4; x++)
                {
                    if (x == 0 && y == 0) inputCanvas.SetColor(x, y, Color.Red);
                    else if (x == 3 && y == 2) inputCanvas.SetColor(x, y, Color.Green);
                    else inputCanvas.SetColor(x, y, Color.Black);
                }
            #endregion

            canvas.SetCanvas(5, 2, inputCanvas);

            Assert.IsTrue(canvas.Width == expected.Width && canvas.Height == expected.Height);

            for (int y = 0; y < canvas.Height; y++)
                for (int x = 0; x < canvas.Width; x++)
                {
                    Color actualColor = canvas.GetColor(x, y);
                    Color expectedColor = expected.GetColor(x, y);
                    Assert.IsTrue(actualColor == expectedColor);
                }
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:43,代码来源:UnitCanvas.cs

示例9: Test_Canvas_SetBorderTop

        public void Test_Canvas_SetBorderTop()
        {
            Canvas canvas = new Canvas(4, 3);

            Canvas expectedCanvas = new Canvas(4, 3);
            expectedCanvas.SetColor(0, 0, Color.Black);
            expectedCanvas.SetColor(1, 0, Color.Black);
            expectedCanvas.SetColor(2, 0, Color.Black);
            expectedCanvas.SetColor(3, 0, Color.Black);

            canvas.SetBorder(0, 0, 4, 3, Color.Black, Aligns.Top, GridType.SolidLine);

            Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height);

            for (int y = 0; y < canvas.Height; y++)
                for (int x = 0; x < canvas.Width; x++)
                {
                    Color actualColor = canvas.GetColor(x, y);
                    Color expectedColor = expectedCanvas.GetColor(x, y);
                    Assert.IsTrue(actualColor == expectedColor);
                }
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:22,代码来源:UnitCanvas.cs

示例10: Test_Canvas_SetBorderPointsLeft

        public void Test_Canvas_SetBorderPointsLeft()
        {
            Canvas canvas = new Canvas(4, 4);

            Canvas expectedCanvas = new Canvas(4, 4);
            expectedCanvas.SetColor(0, 0, Color.Black);
            expectedCanvas.SetColor(0, 3, Color.Black);

            canvas.SetBorder(0, 0, 4, 4, Color.Black, Aligns.Left, GridType.Points);

            Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height);

            for (int y = 0; y < canvas.Height; y++)
                for (int x = 0; x < canvas.Width; x++)
                {
                    Color actualColor = canvas.GetColor(x, y);
                    Color expectedColor = expectedCanvas.GetColor(x, y);
                    Assert.IsTrue(actualColor == expectedColor);
                }
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:20,代码来源:UnitCanvas.cs

示例11: Test_Canvas_ReduceResolution

        public void Test_Canvas_ReduceResolution()
        {
            Canvas canvas = new Canvas(new Resolution(8, 5));
            #region Filling canvas
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 6; x++)
                {
                     if((x == 4 && y == 0) ||
                        (x == 5 && y == 0) ||
                        (x == 5 && y == 1))
                        canvas.SetColor(x, y, Color.Green);
                    else if ((x == 0 && y == 2) ||
                            (x == 1 && y == 2) ||
                            (x == 2 && y == 2) ||
                            (x == 3 && y == 2) ||
                            (x == 2 && y == 3))
                        canvas.SetColor(x, y, Color.Blue);
                    else canvas.SetColor(x, y, Color.Red);
                }
            #endregion

            Canvas expectedCanvas = new Canvas(new Resolution(3, 2));
            #region Filling expected canvas
            for(int y = 0; y < 2; y++)
                for (int x = 0; x < 3; x++)
                {
                    if (x == 2 && y == 0)
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 63, 96, 0));
                    else if (x == 1 && y == 1)
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 63, 0, 191));
                    else if (x == 0 && y == 1)
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 127, 0, 127));
                    else
                        expectedCanvas.SetColor(x, y, Color.FromArgb(255, 255, 0, 0));
                }
            #endregion

            Canvas actualCanvas = canvas.ReduceResolution(3, 2, 2);

            Assert.IsTrue(actualCanvas.Width == expectedCanvas.Width && actualCanvas.Height == expectedCanvas.Height);

            for (int y = 0; y < actualCanvas.Height; y++)
                for (int x = 0; x < actualCanvas.Width; x++)
                {
                    Color actualColor = actualCanvas.GetColor(x, y);
                    Color expectedColor = expectedCanvas.GetColor(x, y);
                    Assert.IsTrue(actualColor == expectedColor);
                }
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:49,代码来源:UnitCanvas.cs

示例12: Test_Canvas_GetInnerCanvas

        public void Test_Canvas_GetInnerCanvas()
        {
            Canvas canvas = new Canvas(new Resolution(10, 8));
            #region Filling canvas
            for(int y = 0; y < 8; y++)
                for (int x = 0; x < 10; x++)
                {
                    if (x == 5 && y == 2) canvas.SetColor(x, y, Color.Red);
                    else canvas.SetColor(x, y, Color.Black);
                }
            #endregion

            Canvas expectedCanvas = new Canvas(new Resolution(3, 4));
            #region Filling canvas
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 3; x++)
                {
                    if (x == 0 && y == 0) expectedCanvas.SetColor(x, y, Color.Red);
                    else expectedCanvas.SetColor(x, y, Color.Black);
                }
            #endregion

            Canvas actual = canvas.GetInnerCanvas(5, 2, new Resolution(3, 4));

            Assert.IsTrue(actual.Width == expectedCanvas.Width && actual.Height == expectedCanvas.Height);

            for (int y = 0; y < actual.Height; y++)
                for (int x = 0; x < actual.Width; x++)
                    Assert.IsTrue(actual.GetColor(x, y) == expectedCanvas.GetColor(x, y));
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:30,代码来源:UnitCanvas.cs

示例13: Decorate

        public void Decorate(Canvas embroidery, Canvas pattern, Settings settings)
        {
            int squareWidth = embroidery.Width / settings.CellsCount;

            if (embroidery.Height < pattern.Height * squareWidth)
                throw new WrongResolutionException("Resolution.Height has to be higher");

            /*Parallel.For with Partitioner*/
               Parallel.ForEach(Partitioner.Create(0, pattern.Height), (rangeHeight) =>
            {
                for (int i = rangeHeight.Item1; i < rangeHeight.Item2; i++)
                    Parallel.ForEach(Partitioner.Create(0, pattern.Width), (rangeWidth) =>
                        {
                            for (int j = rangeWidth.Item1; j < rangeWidth.Item2; j++)
                            {
                                int startX = j * squareWidth;
                                int endX = startX + squareWidth;

                                int startY = i * squareWidth;
                                int endY = startY + squareWidth;

                                for (int y = startY; y < endY; y++)
                                    for (int x = startX; x < endX; x++)
                                        embroidery.SetColor(x, y, pattern.GetColor(j, i));
                            }
                        });
            });

            #region Just parallel.For
            /*
            Parallel.For(0, pattern.Height, i =>
                {

                    Parallel.For(0, pattern.Width, j =>
                    {
                        int startX = j * squareWidth;
                        int endX = startX + squareWidth;

                        int startY = i * squareWidth;
                        int endY = startY + squareWidth;

                        for (int y = startY; y < endY; y++)
                            for (int x = startX; x < endX; x++)
                                embroidery.SetColor(x, y, pattern.GetColor(j, i));
                    });
                });
            */
            #endregion

            #region Obsolete
            /*
            int newX = 0;
            int newY = 0;

            for (int i = 0; i < pattern.Height; i++)
            {
                for (int j = 0; j < pattern.Width; j++)
                {
                    for (int y = newY; y < newY + squareWidth; y++)
                        for (int x = newX; x < newX + squareWidth; x++)
                            embroidery.SetColor(x, y, pattern.GetColor(j, i));

                    newX += squareWidth;
                }

                newY += squareWidth;
                newX = 0;
            }
             */
            #endregion
        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:71,代码来源:CellsDecorator.cs


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