Example #1
0
 public virtual void Init(WriteableBitmap w, IGrap9Attr attr)
 {
     if (attr != null)
     {
         size        = attr.size;
         hard        = attr.hard;
         blend       = attr.blend;
         dilution    = attr.dilution;
         persistence = attr.persistence;
         density     = attr.density;
         space       = attr.space;
         step        = attr.step;
         size_prs    = attr.size_prs;
         size_fade   = attr.size_fade;
         randrota    = attr.randrota;
         randpos     = attr.randpos;
         randsize    = attr.randsize;
         randsharp   = attr.randsharp;
         color       = attr.color;
         bgurl       = attr.bgurl;
         fgurl       = attr.fgurl;
     }
 }
Example #2
0
        public override void Init(WriteableBitmap bmp, IGrap9Attr attr = null)
        {
            var newbg = attr.bgurl != bgurl || attr.fgurl != fgurl || attr.hard != hard;

            base.Init(bmp, attr);
            b      = bmp;
            source = new CanvasRenderTarget(
                device, b.PixelWidth, b.PixelHeight, 96,
                Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                CanvasAlphaMode.Premultiplied
                );
            Canvas = new CanvasRenderTarget(
                device, b.PixelWidth, b.PixelHeight, 96,
                Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                CanvasAlphaMode.Premultiplied
                );
            Invalidate(true);

            try
            {
                if (newbg)
                {
                    if (fgurl != "")
                    {
                        var img = LayerPaint.Img.Create(fgurl);
                        Shape = CanvasBitmap.CreateFromBytes(
                            device, img.PixelBuffer, img.PixelWidth, img.PixelHeight,
                            Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized
                            );
                    }
                    else
                    {
                        var px     = 200;
                        var csize  = Canvas.Size;
                        var sample = new CanvasRenderTarget(device, 2 * px, 2 * px, 96,
                                                            Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, CanvasAlphaMode.Premultiplied
                                                            );
                        var tb = new CanvasRadialGradientBrush(device, new[]  {
                            new CanvasGradientStop()
                            {
                                Color = Color.FromArgb(255, 255, 255, 255), Position = hard
                            },
                            new CanvasGradientStop()
                            {
                                Color = Color.FromArgb(255, 0, 0, 0), Position = 1f
                            },
                        }, CanvasEdgeBehavior.Clamp, CanvasAlphaMode.Straight);
                        using (var s = sample.CreateDrawingSession())
                        {
                            tb.RadiusX = px; tb.RadiusY = px; tb.Center = new Vector2(px, px);
                            s.FillRectangle(0, 0, px * 2, px * 2, tb);
                        }
                        Shape = sample;
                    }
                    if (bgurl != "")
                    {
                        var img = LayerPaint.Img.Create(bgurl);
                        Texture = CanvasBitmap.CreateFromBytes(
                            device, img.PixelBuffer, img.PixelWidth, img.PixelHeight,
                            Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized
                            );
                    }
                    else
                    {
                        Texture = null;
                    }
                    //fgurl = bgurl= "";
                }
            }
            catch (Exception e)
            {
                new Windows.UI.Popups.MessageDialog(e.ToString()).ShowMux();
            }

            Loadd();
        }