示例#1
0
        static System.Drawing.Bitmap CreateBackgroundBmp(int w, int h)
        {
            //----------------------------------------------------
            //1. create background bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h);
            //2. create graphics from bmp
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            // draw a background to show how the mask is working better
            g.Clear(System.Drawing.Color.White);
            int rect_w = 30;

            var v1 = new VertexStore();//todo; use pool

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        VxsHelper.FillVxsSnap(g, new VertexStoreSnap(rect.MakeVxs(v1)), Drawing.Color.Make(.9f, .9f, .9f));
                        v1.Clear();
                    }
                }
            }

            //----------------------------------------------------
            return(bmp);
        }
示例#2
0
        void DrawWithWinGdi(GdiPlusCanvasPainter p)
        {
            int w = 800, h = 600;

            p.Clear(Drawing.Color.White);
            p.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            if (isMaskSliderValueChanged)
            {
                GenerateMaskWithWinGdiPlus(w, h);
            }

            using (System.Drawing.Bitmap background = CreateBackgroundBmp(w, h))
            {
                p.DrawImage(background, 0, 0);
            }

            //draw lion on background
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(w / 2, h / 2));

            using (System.Drawing.Bitmap lionBmp = new System.Drawing.Bitmap(w, h))
                using (System.Drawing.Graphics lionGfx = System.Drawing.Graphics.FromImage(lionBmp))
                {
                    lionGfx.Clear(System.Drawing.Color.White);
                    int   n         = lionShape.NumPaths;
                    int[] indexList = lionShape.PathIndexList;
                    var   colors    = lionShape.Colors;
                    //var lionVxs = lionShape.Path.Vxs;// transform.TransformToVxs(lionShape.Path.Vxs);

                    var lionVxs = new VertexStore();
                    transform.TransformToVxs(lionShape.Path.Vxs, lionVxs);
                    for (int i = 0; i < n; ++i)
                    {
                        VxsHelper.FillVxsSnap(lionGfx,
                                              new VertexStoreSnap(lionVxs, indexList[i]),
                                              colors[i]);
                    }
                    using (var mergeBmp = MergeAlphaChannel(lionBmp, a_alphaBmp))
                    {
                        //gx.InternalGraphics.DrawImage(this.a_alphaBmp, new System.Drawing.PointF(0, 0));
                        //gx.InternalGraphics.DrawImage(bmp, new System.Drawing.PointF(0, 0));
                        p.DrawImage(mergeBmp, 0, 0);
                    }
                }
        }
 public override void Draw(Graphics g)
 {
     //draw a lion here
     var spriteShape = lionFill.GetSpriteShape();
     //---------------------------------------------------------------------------------------------
     {
         g.TranslateTransform(offsetX, offSetY);
         int         j        = spriteShape.NumPaths;
         var         myvxs    = spriteShape.Path.Vxs;
         int[]       pathList = spriteShape.PathIndexList;
         ColorRGBA[] colors   = spriteShape.Colors;
         for (int i = 0; i < j; ++i)
         {
             VxsHelper.FillVxsSnap(g, new VertexStoreSnap(myvxs, pathList[i]), colors[i]);
         }
         g.TranslateTransform(-offsetX, -offSetY);
     }
 }
示例#4
0
        void GenerateMaskWithWinGdiPlus(int w, int h)
        {
            //1. create 32 bits for mask image
            this.a_alphaBmp = new System.Drawing.Bitmap(w, h);
            //2. create graphics based on a_alphaBmp
            using (System.Drawing.Graphics gfxBmp = System.Drawing.Graphics.FromImage(a_alphaBmp))
            {
                gfxBmp.Clear(System.Drawing.Color.Black);
                //ClipProxyImage clippingProxy = new ClipProxyImage(image);
                //clippingProxy.Clear(ColorRGBA.Black);
                VertexSource.Ellipse ellipseForMask = new PixelFarm.Agg.VertexSource.Ellipse();
                System.Random        randGenerator  = new Random(1432);
                int num = (int)maskAlphaSliderValue;
                int lim = num - 1;
                for (int i = 0; i < lim; ++i)
                {
                    ellipseForMask.Reset(randGenerator.Next() % w,
                                         randGenerator.Next() % h,
                                         randGenerator.Next() % 100 + 20,
                                         randGenerator.Next() % 100 + 20,
                                         100);
                    // set the color to draw into the alpha channel.
                    // there is not very much reason to set the alpha as you will get the amount of
                    // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                    //rasterizer.AddPath(ellipseForMask.MakeVxs());
                    //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                    //   ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                    var v1 = GetFreeVxs();
                    VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v1), Drawing.Color.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                    ReleaseVxs(ref v1);
                }
                //the last one
                ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                //fill
                var v2 = GetFreeVxs();
                VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v2), Drawing.Color.Make(0, 0, 0, 255));
                v2.Clear();// reuse later
                //rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255));
                ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                //rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(255, 0, 0, 255));

                VxsHelper.FillVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(v2), Drawing.Color.Make(255, 0, 0, 255));

                ReleaseVxs(ref v2);
                //for (i = 0; i < num; i++)
                //{
                //    if (i == num - 1)
                //    {
                //        ellipseForMask.Reset(Width / 2, Height / 2, 110, 110, 100);
                //        //fill
                //        VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), new ColorRGBA(0, 0, 0, 255));
                //        //rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                //        //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(0, 0, 0, 255));
                //        ellipseForMask.Reset(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                //        //rasterizer.AddPath(ellipseForMask.MakeVertexSnap());
                //        //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack, new ColorRGBA(255, 0, 0, 255));
                //        VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), new ColorRGBA(255, 0, 0, 255));
                //    }
                //    else
                //    {
                //        ellipseForMask.Reset(randGenerator.Next() % w,
                //                 randGenerator.Next() % h,
                //                 randGenerator.Next() % 100 + 20,
                //                 randGenerator.Next() % 100 + 20,
                //                 100);
                //        // set the color to draw into the alpha channel.
                //        // there is not very much reason to set the alpha as you will get the amount of
                //        // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                //        //rasterizer.AddPath(ellipseForMask.MakeVxs());
                //        //sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, sclnPack,
                //        //   ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                //        VxsHelper.DrawVxsSnap(gfxBmp, ellipseForMask.MakeVertexSnap(), ColorRGBA.Make((int)((float)i / (float)num * 255), 0, 0, 255));
                //    }
                //}
            }
        }