Пример #1
0
        private void Draw(ImageView imageView, int times)
        {
            var start = DateTime.Now;
            PixelsBuffer buffer = new PixelsBuffer(600, 600);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.Transparent);
            //create fill for drawing
            Fill fill = new Fill(Colors.Transparent);
            //fill.Opacity = 0.3;
            //draw content
            var coords1 = GetPath(1);
            var coords2 = GetPath(0);
            var coords3 = GetPath(2);

            var path = GetPath();
            var startDraw = DateTime.Now;
            int step = 5;
            for (int i = 0; i < times; i++)
            {
                //drawer.DrawRectangle(fill, 10, 10, 300, 300);
                //drawer.DrawEllipse(fill, 200, 200, 120, 200);
                //drawer.DrawPolygon(fill, coords1);
                //drawer.DrawPolygon(fill, coords2);
                //drawer.DrawPolygon(fill, coords3);

                //draw content
                //drawer.Rotate(15);
                //drawer.Scale(0.3, 0.3);
                //drawer.DrawPath(fill, path);

                var margin = i / 10 * step;

                PixelsBuffer view = buffer.CreateView(margin, margin, buffer.Width - margin * 2, buffer.Height - margin * 2, true);
                DrawFrame(view, Colors.OrangeRed);
                DrawLine(view, Colors.Olive);

            }
            DrawLion(buffer, 200, 200);

            if (bmp != null)
                bmp.Dispose();
            bmp = BufferToBitmap.GetBitmap(buffer);

            //show to screen
            var icon = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.Icon);

            imageView.SetImageBitmap(BufferToBitmap.Overlay(new Bitmap[] { icon, bmp }));
            Android.Util.Log.Debug("Draw " + times, "Draw: " + (DateTime.Now - startDraw).TotalSeconds.ToString() + " Total: " + (DateTime.Now - start).TotalSeconds.ToString());
        }
        private void btnDrawEllipse_Click(object sender, EventArgs e)
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.Yellow;

            //draw content
            drawer.DrawEllipse(fill, 200, 200, 180, 100);

            //show to screen
            DisplayBuffer(buffer);
        }
        private void btnDrawRoundRect_Click(object sender, EventArgs e)
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.DarkOrange;

            //draw content
            drawer.DrawRoundedRectangle(fill, 50, 50, 300, 200, 15, 15);

            //show to screen
            DisplayBuffer(buffer);
        }
Пример #4
0
        /// <summary>
        /// Render a star shape to buffer
        /// </summary>
        void DrawStar(PixelsBuffer buffer, Color color, Color background)
        {
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(background);

            Fill fill = new Fill(color);

            double[] coordinates = TestFactory.Star();
            TestFactory.Scale(coordinates, 2.0);

            //drawer.DrawRectangle(stroke, 0, 0, buffer.Width, buffer.Height);
            drawer.DrawPolygon(fill, coordinates);
        }
Пример #5
0
        void DrawLion(PixelsBuffer buffer, int x, int y)
        {
            //create a new drawing context
            //PixelBuffer buffer = new PixelBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);

            //get coordinates and colors
            double[][] polygons = LionPathHelper.GetLionPolygons();
            Cross.Drawing.Color[] colors = LionPathHelper.GetLionColors();

            //iterate all polygons and draw them
            double[] coordinates = null;
            drawer.Translate(x, y);
            for (int i = 0; i < polygons.Length; i++)
            {
                coordinates = polygons[i];
                Fill fill = new Fill(colors[i]);
                drawer.DrawPolygon(fill, coordinates);
            }
        }
        private void btnDrawPolygon_Click(object sender, EventArgs e)
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.MistyRose;

            //populate polygon coordinate data
            double[] coordinates = new double[]
            {
                30, 300,
                150, 40,
                300, 260,
                130, 200,
                //30, 300 //the last point is omitted to show that the end point is important
                          //for rendering stroke
            };

            //draw content
            drawer.DrawPolygon(fill, coordinates);

            //show to screen
            DisplayBuffer(buffer);
        }
        void DrawLion()
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //get coordinates and colors
            double[][] polygons = LionPathHelper.GetLionPolygons();
            Color[] colors = LionPathHelper.GetLionColors();

            //iterate all polygons and draw them
            double[] coordinates = null;
            for (int i = 0; i < polygons.Length; i++)
            {
                coordinates = polygons[i];
                Fill fill = new Fill(colors[i]);
                drawer.DrawPolygon(fill, coordinates);
            }

            //show to screen
            DisplayBuffer(buffer);
        }
        private void btnDrawTest_Click(object sender, EventArgs e)
        {
            if (lstTests.SelectedIndex < 0) lstTests.SelectedIndex = 0;

            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(600, 600);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.Black;

            //populate polygon coordinate data
            double[] coordinates = null;
            switch (lstTests.SelectedIndex)
            {
                case 0:
                    coordinates = TestFactory.Triangle();
                    TestFactory.Scale(coordinates, 5.0);
                    break;

                case 1:
                    coordinates = TestFactory.Star();
                    TestFactory.Scale(coordinates, 5.0);
                    break;

                case 2:
                    coordinates = TestFactory.Crown();
                    TestFactory.Scale(coordinates, 5.0);
                    break;

                case 3:
                    coordinates = TestFactory.CirclePattern1(buffer.Width, buffer.Height);
                    break;

                case 4:
                    coordinates = TestFactory.CirclePattern2(buffer.Width, buffer.Height);
                    break;

                case 5:
                    coordinates = TestFactory.Complex1();
                    break;

                case 6:
                    coordinates = TestFactory.Complex2();
                    break;

                case 7:
                    coordinates = TestFactory.Complex3();
                    break;

                case 8:
                    DrawLion();
                    break;
            }


            if (coordinates != null)
            {
                //draw content
                drawer.DrawPolygon(fill, coordinates);

                //show to screen
                DisplayBuffer(buffer);
            }
        }
        private void btnDrawPath_Click(object sender, EventArgs e)
        {
            //create a new drawing context
            PixelsBuffer buffer = new PixelsBuffer(400, 400);
            IDrawer drawer = new Drawer(buffer);
            drawer.Clear(Colors.White);

            //create fill for drawing
            Fill fill = Fills.MistyRose;

            //create path
            DrawingPath path = new DrawingPath();
            path.MoveTo(200, 100);
            path.CurveTo(200, 350, 340, 30, 360, 200);
            path.CurveTo(200, 100, 40, 200, 60, 30);

            //draw content
            drawer.Rotate(15);
            drawer.Scale(0.3, 0.3);
            drawer.DrawPath(fill, path);

            //show to screen
            DisplayBuffer(buffer);
        }