Пример #1
0
 public CustomScanlineRasToBmp_EnlargedV2(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = Graphics2D.CreateFromImage(destImage);
 }
Пример #2
0
        public FloodFillDemo()
        {
            BackgroundColor = Color.White;
            imageToFillOn   = new ActualImage(400, 300, PixelFormat.ARGB32);
            ImageGraphics2D imageToFillGraphics = Graphics2D.CreateFromImage(imageToFillOn);

            imageToFillGraphics.Clear(Color.White);
            //imageToFillGraphics.DrawString("Click to fill", 20, 30);
            imageToFillGraphics.Circle(new Vector2(200, 150), 35, Color.Black);
            imageToFillGraphics.Circle(new Vector2(200, 150), 30, Color.Green);
            imageToFillGraphics.Rectangle(20, 50, 210, 280, Color.Black);
            imageToFillGraphics.Rectangle(imageToFillOn.Bounds, Color.Blue);
            Random rand = new Random();

            var stroke1 = new Stroke(1);
            var v1      = GetFreeVxs();
            var v2      = GetFreeVxs();

            for (int i = 0; i < 20; i++)
            {
                Ellipse elipse = new Ellipse(rand.Next(imageToFillOn.Width), rand.Next(imageToFillOn.Height), rand.Next(10, 60), rand.Next(10, 60));
                imageToFillGraphics.Render(stroke1.MakeVxs(elipse.MakeVxs(v1), v2), Color.Black);
            }
            ReleaseVxs(ref v1);
            ReleaseVxs(ref v2);
            this.PixelSize = 32;
            this.Gamma     = 1;
        }
 public MyMiniAggCanvasRenderElement(RootGraphic rootgfx, int width, int height)
     : base(rootgfx, width, height)
 {
     this.actualImage = new ActualImage(width, height, PixelFarm.Agg.PixelFormat.ARGB32);
     this.gfx2d       = Graphics2D.CreateFromImage(actualImage);
     needUpdate       = true;
 }
Пример #4
0
 public CustomScanlineRasToBmp_EnlargedSubPixelRendering(double size, ActualImage destImage)
 {
     this.ScanlineRenderMode = Agg.ScanlineRenderMode.Custom;
     m_size   = size;
     m_square = new Square(size);
     gfx      = Graphics2D.CreateFromImage(destImage);
     lcdLut   = new Sample_AADemoTest3.AggLcdDistributionLookupTable(primary, 2.0 / 9, 1.0 / 9);
 }
 public MiniAggCanvasRenderElement(RootGraphic rootgfx, int width, int height)
     : base(rootgfx, width, height)
 {
     this.actualImage = new ActualImage(width, height, PixelFarm.Agg.PixelFormat.ARGB32);
     this.gfx2d       = Graphics2D.CreateFromImage(actualImage);
     this.painter     = new AggCanvasPainter((ImageGraphics2D)gfx2d);
     needUpdate       = true;
     this.BackColor   = Color.White;
 }
Пример #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;

            using (System.Drawing.Font ff = new Font("tahoma", fontSize))
                using (Graphics g = this.pictureBox1.CreateGraphics())
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.Clear(Color.White);

                    var winFont      = PixelFarm.Agg.Fonts.GdiPathFontStore.LoadFont("tahoma", (int)fontSize);
                    var winFontGlyph = winFont.GetGlyph(testChar);

                    //convert Agg vxs to bitmap
                    int bmpW = 50;
                    int bmpH = 50;
                    using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                    {
                        ActualImage actualImage = new ActualImage(bmpW, bmpH, PixelFarm.Agg.Image.PixelFormat.Rgba32);
                        Graphics2D  gfx         = Graphics2D.CreateFromImage(actualImage);
                        var         vxs         = winFontGlyph.originalVxs;
                        gfx.Render(vxs, ColorRGBA.Black);
                        //test subpixel rendering
                        vxs = PixelFarm.Agg.Transform.Affine.TranslateToVxs(vxs, 15, 0);
                        gfx.UseSubPixelRendering = true;
                        gfx.Render(vxs, ColorRGBA.Black);
                        PixelFarm.Agg.Image.BitmapHelper.CopyToWindowsBitmap(
                            actualImage, //src from actual img buffer
                            bufferBmp,   //dest to buffer bmp
                            new RectInt(0, 0, bmpW, bmpH));
                        //-----------------------------------------
                        bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        g.DrawImage(bufferBmp, new Point(0, 30));
                    }
                    //----------------------------------------------



                    //----------------------------------------------
                    //compare with GraphicsPath's Font
                    using (GraphicsPath gpath = new GraphicsPath())
                    {
                        gpath.AddString(testChar.ToString(), ff.FontFamily, 1, ff.Size,
                                        new Point(0, 0), null);
                        g.FillPath(Brushes.Black, gpath);
                        //g.DrawPath(Pens.Black, gpath);
                    }
                    //-------------------------------------------------
                    //Compare with Gdi+ Font
                    g.DrawString(testChar.ToString(), ff, Brushes.Black, new PointF(0, 50));
                }
        }
Пример #7
0
        private void button4_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;


            using (Graphics g = this.pictureBox1.CreateGraphics())
            {
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.Clear(Color.White);

                //convert Agg vxs to bitmap
                int bmpW = 500;
                int bmpH = 500;
                using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                {
                    ActualImage actualImage = new ActualImage(bmpW, bmpH, PixelFarm.Agg.Image.PixelFormat.Rgba32);
                    Graphics2D  gfx         = Graphics2D.CreateFromImage(actualImage);
                    var         vxs         = new VertexStore();

                    //vxs.AddMoveTo(0, 0);
                    ////vxs.AddP3c(100, 0);
                    ////vxs.AddP3c(100,150);
                    ////vxs.AddLineTo(0,0);
                    //vxs.AddLineTo(0, 0);
                    //vxs.AddP3c(100, 0);
                    ////vxs.AddLineTo(100, 0);
                    ////vxs.AddLineTo(100, 150);
                    //vxs.AddP3c(100, 150);
                    //vxs.AddLineTo(0, 150);
                    //vxs.AddCloseFigure();

                    //PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener();
                    //vxs = cflat.MakeVxs(vxs);

                    gfx.Render(vxs, ColorRGBA.Black);
                    //test subpixel rendering
                    vxs = PixelFarm.Agg.Transform.Affine.TranslateToVxs(vxs, 15, 0);
                    gfx.UseSubPixelRendering = true;
                    gfx.Render(vxs, ColorRGBA.Black);
                    PixelFarm.Agg.Image.BitmapHelper.CopyToWindowsBitmap(
                        actualImage, //src from actual img buffer
                        bufferBmp,   //dest to buffer bmp
                        new RectInt(0, 0, bmpW, bmpH));
                    //-----------------------------------------
                    bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    g.DrawImage(bufferBmp, new Point(0, 30));
                }
            }
        }
Пример #8
0
        public override void Load()
        {
            //lion fill test
            FormTestWinGLControl form   = new FormTestWinGLControl();
            CanvasGL2d           canvas = new CanvasGL2d(this.Width, this.Height);
            var lionFill = new LionFillSprite();
            //----------
            //draw lion on software layer
            ActualImage actualImage = new ActualImage(800, 600, PixelFarm.Agg.Image.PixelFormat.Rgba32);
            Graphics2D  g2d         = Graphics2D.CreateFromImage(actualImage);
            GLBitmap    bmp         = null;

            form.SetGLPaintHandler((o, s) =>
            {
                canvas.Clear(PixelFarm.Drawing.Color.White);
                //-------------------------------------
                // draw lion from bitmap to GL screen
                if (bmp == null)
                {
                    lionFill.OnDraw(g2d);
                    bmp = new GLBitmap(new LazyAggBitmapBufferProvider(actualImage));
                }
                //lion is inverted from software layer ,
                //so... we use DrawImageInvert()
                int xpos = 0;
                int w    = bmp.Width;
                int h    = bmp.Height;

                for (int i = 0; i < 3; ++i)
                {
                    canvas.DrawImage(bmp, xpos, 50, w, h);
                    w     = (int)(w * 1.2);
                    h     = (int)(h * 1.2);
                    xpos += 150;
                }
                w    = bmp.Width;
                h    = bmp.Height;
                xpos = 0;
                for (int i = 0; i < 2; ++i)
                {
                    w     = (int)(w * 0.75);
                    h     = (int)(h * 0.75);
                    xpos -= 50;
                    canvas.DrawImage(bmp, xpos, 50, w, h);
                }
            });

            form.Show();
        }
        public Graphics2D CreateNewGraphic2D()
        {
            Graphics2D graphics2D;

            if (actualImage != null)
            {
                graphics2D = Graphics2D.CreateFromImage(actualImage);
            }
            else
            {
                throw new NotSupportedException();
                //graphics2D = bitmapBackBuffer.backingImageBufferFloat.NewGraphics2D();
            }

            return(graphics2D);
        }
Пример #10
0
 ImageGraphics2D Initialize(int width, int height, int bitDepth)
 {
     if (width > 0 && height > 0)
     {
         if (bitDepth != 32)
         {
             throw new NotImplementedException("Don't support this bit depth yet.");
         }
         else
         {
             var actualImage = new ActualImage(width, height, PixelFormat.ARGB32);
             bitmapBackBuffer.Initialize(width, height, bitDepth, actualImage);
             return(Graphics2D.CreateFromImage(actualImage));
         }
     }
     throw new NotSupportedException();
 }
        public Graphics2D Initialize(int width, int height, int bitDepth)
        {
            if (width > 0 && height > 0)
            {
                this.width  = width;
                this.height = height;
                switch (bitDepth)
                {
                case 24:
                    bufferBmp   = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    actualImage = new ActualImage(width, height, PixelFarm.Agg.Image.PixelFormat.Rgb24);
                    bufferGfx   = Graphics.FromImage(bufferBmp);
                    return(Graphics2D.CreateFromImage(actualImage));

                case 32:

                    bufferBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                    //windowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    //widowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                    //widowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    //32bppPArgb
                    actualImage = new ActualImage(width, height, PixelFarm.Agg.Image.PixelFormat.Rgba32);
                    bufferGfx   = Graphics.FromImage(bufferBmp);

                    return(Graphics2D.CreateFromImage(actualImage));

                case 128:
                //windowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                //backingImageBufferByte = null;
                //backingImageBufferFloat = new ImageBufferFloat(width, height, 128, new BlenderBGRAFloat());
                //break;

                default:
                    throw new NotImplementedException("Don't support this bit depth yet.");
                }
            }
            throw new NotSupportedException();
        }