예제 #1
0
        private void btnBufferInBufferDraw_Click(object sender, EventArgs e)
        {
            //create & render to main buffer
            PixelsBuffer buffer = new PixelsBuffer(width, height);

            DrawStar(buffer, Colors.Red, Colors.White);

            //create a sub view (50, 50, 100, 100) - inversed
            PixelsBuffer view = buffer.CreateView(50, 250, 100, 100, true);

            DrawStar(view, Colors.Blue, Colors.YellowGreen);

            //create a sub view (50, 50, 100, 100)
            view = buffer.CreateView(250, 150, 100, 100);
            DrawStar(view, Colors.Goldenrod, Colors.LemonChiffon);

            //show to screen
            DisplayBuffer(buffer);

            #region Description
            string msg = "This example demonstrates that logical views with different coordinate systems can be attached to the same pixel buffer";

            txtDescription.Text = msg;
            #endregion
        }
예제 #2
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());
        }
예제 #3
0
        private void btnBufferInBuffer_Click(object sender, EventArgs e)
        {
            //create main buffer
            PixelsBuffer buffer = new PixelsBuffer(width, height);

            //create a sub view (100 pixels margin)
            int margin = 100;

            #region Approach 1
            //calculate new view's parameter by hand
            //then attach the new view to main buffer

            /*
             * int viewStride = -buffer.Stride; //inverse coordinate system of view
             * int viewOffset = buffer.GetPixelIndex(margin, margin);
             * PixelBuffer view = new PixelBuffer();
             * view.Attach(buffer, width - margin * 2, height - margin * 2, viewStride, viewOffset);
             */
            #endregion

            #region Approach 2
            //a much easier way to create sub-view

            PixelsBuffer view = buffer.CreateView(margin, margin, width - margin * 2, height - margin * 2, true);
            #endregion

            //render to main buffer
            DrawLine(buffer, Colors.Red);
            DrawFrame(buffer, Colors.Red);

            //render to sub view
            DrawLine(view, Colors.Blue);
            DrawFrame(view, Colors.Blue);

            //show to screen
            DisplayBuffer(buffer);

            #region Description
            string msg = "This example creates a main buffer, render pixels to it. Then, create a sub-view with inversed y-axis, and render to this view.";

            txtDescription.Text = msg;
            #endregion
        }