Example #1
0
        //Merge All:全部合并
        private void LayerMergeAllButton_Click(object sender, RoutedEventArgs e)
        {
            App.Model.isCanUndo = false;//关闭撤销

            //更新撤销类
            Undo undo = new Undo();

            undo.CollectionInstantiation(App.Model.Index, App.Model.Layers);
            App.UndoAdd(undo);

            //新建渲染目标层
            CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, App.Model.Width, App.Model.Height);

            using (CanvasDrawingSession ds = crt.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);

                //全部合并
                ICanvasImage ci = App.Model.NullRenderTarget;
                for (int i = App.Model.Layers.Count - 1; i >= 0; i--) //自下而上渲染
                {
                    ci = App.Render(App.Model.Layers[i], ci);         //渲染
                }
                ds.DrawImage(ci);
            }

            //删掉所有图层
            App.Model.Layers.Clear();
            //插入层
            Layer l = new Layer {
                Name = App.resourceLoader.GetString("/Layer/NameMerge_"), CanvasRenderTarget = crt,
            };

            if (App.Model.isLowView)
            {
                l.LowView();
            }
            else
            {
                l.SquareView();
            }

            l.SetWriteableBitmap(App.Model.VirtualControl);
            App.Model.Layers.Add(l);
            App.Model.Index = 0;                            //不产生撤销类的改变索引的方法,适用于撤销的操作

            App.Model.isCanUndo   = true;                   //开启撤销
            App.Model.LayersCount = App.Model.Layers.Count; //Undo:撤销

            Jugde();                                        //判断
        }
Example #2
0
        ///<summary>
        ///Draw the GenericItem
        ///</summary>
        ///<param name= "cds"> A surface to draw on.</param>
        public virtual void Draw(CanvasDrawingSession cds)
        {
            if (null == Bitmap)
            {
                return;
            }

            cds.DrawImage(Bitmap, Location);

            if (DrawBoundingRectangle)
            {
                cds.DrawRectangle(BoundingRectangle, Windows.UI.Colors.Purple);
            }
        }
Example #3
0
        static public async Task <CompositionDrawingSurface> LoadFromUri(Uri uri)
        {
            CanvasBitmap CBitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);

            CompositionDrawingSurface DrawingSurface = _compositionDevice.CreateDrawingSurface(CBitmap.Size, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (CanvasDrawingSession DraingSession = CanvasComposition.CreateDrawingSession(DrawingSurface))
            {
                DraingSession.Clear(Color.FromArgb(0, 0, 0, 0));
                DraingSession.DrawImage(CBitmap, new Rect(0, 0, CBitmap.Size.Width, CBitmap.Size.Height));
            }

            return(DrawingSurface);
        }
Example #4
0
 public void ProcessFrame(ProcessVideoFrameContext context)
 {
     using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface))
         using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface))
             using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
             {
                 var saturation = new SaturationEffect()
                 {
                     Source     = inputBitmap,
                     Saturation = this.Saturation
                 };
                 ds.DrawImage(saturation);
             }
 }
Example #5
0
        /// <summary>
        /// Draw dotted-line.
        /// </summary>
        /// <param name="drawingSession"> The drawing-session. </param>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="dottedLineBrush"> The brush. </param>
        /// <param name="dottedLineImage"> The image. </param>
        /// <param name="width"> The width. </param>
        /// <param name="height"> The height. </param>
        /// <param name="x"> The X-axis distance. </param>
        /// <param name="y"> The Y-axis distance. </param>
        public static void DrawDottedLine(this CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, DottedLineBrush dottedLineBrush, DottedLineImage dottedLineImage, float width, float height, float x = 0, float y = 0)
        {
            ICanvasImage image        = dottedLineImage.Output;
            Rect         canvasBounds = new Rect(x, y, width, height);

            CanvasCommandList commandList = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession ds = commandList.CreateDrawingSession())
            {
                ds.FillRectangle(canvasBounds, dottedLineBrush.Brush);
                ds.DrawImage(image, x, y, canvasBounds, 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.DestinationIn);
            }
            drawingSession.DrawImage(commandList);
        }
Example #6
0
        private void DrawBlock(CanvasDrawingSession ds, int cellX, int cellY, int cellColor, int screenDispX = 0, int screenDispY = 0)
        {
            if (cellY < 0)
            {
                return; // Invisible
            }
            int screenX = cellX * cellSize + screenDispX;
            int screenY = cellY * cellSize + screenDispY;

            Rect destinationRectangle = new Rect(screenX, screenY, cellSize, cellSize);
            Rect sourceRectangle      = new Rect(42 * 2 * cellColor, 0, 42, 42);

            ds.DrawImage(piecesBitmap, destinationRectangle, sourceRectangle);
        }
        public virtual CanvasBitmap GetImage(bool overlay, int layer)
        {
            CanvasDevice       device    = CanvasDevice.GetSharedDevice();
            CanvasRenderTarget offscreen = new CanvasRenderTarget(device, 32, 32, 96);

            using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
            {
                if (lower != null)
                {
                    ds.DrawImage(lower.GetImage(false));
                }

                if (upper != null)
                {
                    if (lower.getType() == Block.Type.CLONEMACHINE)
                    {
                        ds.DrawImage(upper.GetImage(true));
                    }
                    else
                    {
                        ds.DrawImage(upper.GetImage(false));
                    }
                }

                if (visitorLow != null)
                {
                    ds.DrawImage(visitorLow.GetImage(true));
                }

                if (visitorHigh != null)
                {
                    ds.DrawImage(visitorHigh.GetImage(true));
                }
            }

            return(offscreen);
        }
        //Posterize:多色调分印
        private void PosterizeButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            flyout.Hide();

            Layer l = App.Model.Layers[App.Model.Index];

            //如果图层不可视或透明
            if (l.Visual == false || l.Opacity <= 0)
            {
                App.Tip(App.resourceLoader.GetString("/Layer/Hided_"));
            }
            else
            {
                //Undo:撤销
                Undo undo = new Undo();
                undo.TargeInstantiation(App.Model.Index, App.Model.CurrentRenderTarget);
                App.UndoAdd(undo);

                using (CanvasDrawingSession ds = l.CanvasRenderTarget.CreateDrawingSession())
                {
                    if (App.Model.isAnimated == false) //清空:如果无选区
                    {
                        ds.Clear(Colors.Transparent);
                    }
                    else if (App.Model.isAnimated == true)  //选区内清空:如果有选区
                    {
                        ds.DrawImage(App.Model.MaskRenderTarget, 0, 0, App.Model.MaskRenderTarget.Bounds, 1, CanvasImageInterpolation.Linear, CanvasComposite.DestinationOut);
                    }

                    ds.DrawImage(Adjust.GetPosterize(App.Model.SecondSourceRenderTarget));
                }

                l.SetWriteableBitmap(App.Model.VirtualControl); //刷新缩略图
                App.Model.isReRender = true;                    //重新渲染
                App.Model.Refresh++;                            //画布刷新
            }
        }
Example #9
0
        protected virtual void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                                    , CanvasSpriteBatch spriteBatch
#endif
                                    )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                //float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                //float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                //float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, 1 /*alpha*/), bitmapCenter,
                                     particle.Rotation - 1.5708f, new Vector2(particle.ScaleX, particle.ScaleY /*scale*/), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation - 1.5708f, bitmapCenter) *
                                    Matrix3x2.CreateScale(/*scale*/ particle.ScaleX, particle.ScaleY, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, 1 /*alpha*/, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
        private async void CopyCopyButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            foreach (Object photoFile in AdaptiveGridViewControl.SelectedItems)
            {
                if (photoFile is PhotoFile item)//as转换
                {
                    var NewName = Named(item.Name);
                    //复制文件
                    var    xDoc = XDocument.Load(item.Path);
                    string path = ApplicationData.Current.LocalFolder.Path + "/" + NewName + ".photo"; //将XML文件加载进来
                    xDoc.Save(path);


                    //6、缩略图 (裁切成宽高最大256的图片)

                    //宽高
                    int Width  = (int)xDoc.Descendants("Width").Single();
                    int Height = (int)xDoc.Descendants("Height").Single();

                    //渲染目标
                    string Target = xDoc.Descendants("MainRenderTarget").Single().Value;
                    byte[] bytes  = Convert.FromBase64String(Target); App.Model.MainRenderTarget = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                    App.Model.MainRenderTarget.SetPixelBytes(bytes);

                    //缩略图缩放比例
                    float scale = Width < Height ? 256.0f / Width : 256.0f / Height;

                    //缩放后宽高并确定左右上下偏移
                    float W = scale * Width;
                    float H = scale * Height;

                    CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, W, H);
                    using (CanvasDrawingSession ds = crt.CreateDrawingSession())
                    {
                        //绘制缩略图
                        ds.DrawImage(new ScaleEffect
                        {
                            Source = App.Model.MainRenderTarget,
                            Scale  = new Vector2(scale)
                        });
                    }
                    Library.Image.SavePng(ApplicationData.Current.LocalFolder, crt, NewName);
                }
            }

            Task.Delay(200);
            GridViewLoaded();
            InAppNotificationDismiss(CopyInAppNotification);//Notification:通知驳回
        }
Example #11
0
        private void StretchContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            WidthNumberPicker.ValueChange  -= WidthNumberPicker_ValueChange;
            HeightNumberPicker.ValueChange -= HeightNumberPicker_ValueChange;

            float     xs     = 1f / App.Model.Width * Width;
            float     ys     = 1f / App.Model.Height * Height;
            Matrix3x2 Matrix = Matrix3x2.CreateScale(xs, ys);

            //跟随宽高
            App.Model.Width        = Width;
            App.Model.Height       = Height;
            App.Model.CanvasWidth  = Width;
            App.Model.CanvasHeight = Height;

            foreach (Layer L in App.Model.Layers)
            {
                CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, Width, Height);
                using (CanvasDrawingSession ds = crt.CreateDrawingSession())
                {
                    ds.DrawImage(new Transform2DEffect {
                        Source = L.CanvasRenderTarget, TransformMatrix = Matrix
                    });
                }
                L.CanvasRenderTarget = crt;
                if (App.Model.isLowView)
                {
                    L.LowView();
                }
                else
                {
                    L.SquareView();
                }
                L.SetWriteableBitmap(App.Model.VirtualControl);
            }

            //初始化
            App.Initialize(App.Model.VirtualControl, Width, Height);
            App.Model.MaskAnimatedTarget = new CanvasRenderTarget(App.Model.AnimatedControl, Width, Height);

            App.Model.isReRender = true; //重新渲染
            App.Model.Refresh++;         //画布刷新

            //Undo:撤销
            App.Model.Undos.Clear();//清空
            App.Model.UndoIndex = 0;
            App.Model.isUndo    = false;
            App.Model.isRedo    = false;
        }
Example #12
0
        //初始化裁切渲染目标
        public static void InitializeCrop()
        {
            using (CanvasDrawingSession ds = App.Model.SecondTopRenderTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);

                ICanvasImage ci = App.Model.NullRenderTarget;
                for (int i = App.Model.Layers.Count - 1; i >= 0; i--) //自下而上渲染
                {
                    ci = App.Render(App.Model.Layers[i], ci);         //渲染
                }
                ds.DrawImage(ci);
            }
            修图.BarPage.OtherPage.Crop.Render();
        }
Example #13
0
 public static void Copy()
 {
     if (App.Model.isAnimated == true)//选区存在
     {
         App.Model.Clipboard = new CanvasRenderTarget(App.Model.VirtualControl, (float)App.Model.MaskRect.Width, (float)App.Model.MaskRect.Height);
         using (CanvasDrawingSession ds = App.Model.Clipboard.CreateDrawingSession())
         {
             ds.DrawImage(App.Model.CurrentRenderTarget, (float)-App.Model.MaskRect.X, (float)-App.Model.MaskRect.Y);
             //扣外留内
             CanvasComposite compositeMode = CanvasComposite.DestinationIn;
             ds.DrawImage(App.Model.MaskRenderTarget, (float)-App.Model.MaskRect.X, (float)-App.Model.MaskRect.Y, App.Model.MaskRenderTarget.Bounds, 1, CanvasImageInterpolation.Linear, compositeMode);
         }
     }
     else if (App.Model.isAnimated == false)//选区不存在
     {
         var rect = App.GetCurrentBounds();
         App.Model.Clipboard = new CanvasRenderTarget(App.Model.VirtualControl, (float)rect.Width, (float)rect.Height);
         using (CanvasDrawingSession ds = App.Model.Clipboard.CreateDrawingSession())
         {
             ds.DrawImage(App.Model.CurrentRenderTarget, (float)-rect.X, (float)-rect.Y);
         }
     }
     App.Model.isClipboard = true;//存在剪切板
 }
Example #14
0
        private void DrawBackImage(CanvasDrawingSession graphics, double scale)
        {
            if (_image != null)
            {
                Rect des = GetImageDrawingRect();
                des.X      *= scale;
                des.Y      *= scale;
                des.Width  *= scale;
                des.Height *= scale;

                var image = ApplyFilterTemplate(_image);

                graphics.DrawImage(image, des, _image.Bounds);
            }
        }
Example #15
0
        private void DrawBackImage(CanvasDrawingSession graphics, double scale)
        {
            if (_image != null)
            {
                Rect des = GetImageDrawingRect();
                des.X      *= scale;
                des.Y      *= scale;
                des.Width  *= scale;
                des.Height *= scale;

                ICanvasImage image = GetBrightnessEffect(_image);

                graphics.DrawImage(image, des, _image.Bounds);
            }
        }
Example #16
0
        private void DrawBitmap1(CanvasDrawingSession ds, Size size)
        {
            Rect rect = new Rect(size.Width / 2,
                                 size.Height / 2,
                                 size.Width / 2,
                                 size.Height / 2);


            if (bitmap1 != null)
            {
                var sourceRect = new Rect(0, 0, bitmap1.GetBounds(CanvasDevice.GetSharedDevice()).Width, bitmap1.GetBounds(CanvasDevice.GetSharedDevice()).Height);

                ds.DrawImage(bitmap1, rect, sourceRect);
            }
        }
Example #17
0
        private async Task Save_InkedImagetoFile(StorageFile saveFile)
        {
            try
            {
                sharefile = await ApplicationData.Current.LocalFolder.CreateFileAsync("imgshare.png", CreationCollisionOption.ReplaceExisting);

                CachedFileManager.DeferUpdates(sharefile);
                using (var outStream = await sharefile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("inkSample");

                    CanvasDevice device = CanvasDevice.GetSharedDevice();
                    var          image  = await CanvasBitmap.LoadAsync(device, file.Path);

                    using (var renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, image.Dpi))
                    {
                        using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                        {
                            ds.Clear(Colors.White);
                            ds.DrawImage(image, new Rect(0, 0, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight));
                            ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
                        }
                        await renderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png);
                    }
                    image.Dispose();
                    Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sharefile);

                    if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                    {
                        if (saveFile != null)
                        {
                            await sharefile.CopyAndReplaceAsync(saveFile);

                            MainPage.ncSettings.objValue    = "Photo has been saved successfully!";
                            MainPage.ncSettings.setSettings = "msgNotify";
                            inkCanvas.InkPresenter.StrokeContainer.Clear();
                            await Task.Delay(new TimeSpan(0, 0, 1));

                            this.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
            catch (Exception)
            {
                UtilityClass.MessageDialog("An error occured while saving photo, Please try again", "An error occured");
            }
        }
        private void ConstructCanvas()
        {
            this.CanvasControl.SizeChanged += (s, e) =>
            {
                if (e.NewSize == e.PreviousSize)
                {
                    return;
                }
                this.Size.SIzeChange((float)e.NewSize.Width, (float)e.NewSize.Height);
            };
            this.CanvasControl.CreateResources += (sender, args) =>
            {
                float width  = (float)sender.ActualWidth;
                float height = (float)sender.ActualHeight;
                this.GrayAndWhiteBackground = new CanvasRenderTarget(sender, width, height);

                using (CanvasDrawingSession drawingSession = this.GrayAndWhiteBackground.CreateDrawingSession())
                {
                    CanvasBitmap bitmap     = GreyWhiteMeshHelpher.GetGreyWhiteMesh(sender);
                    ICanvasImage extendMesh = GreyWhiteMeshHelpher.GetBorderExtendMesh(height / 4, bitmap);
                    drawingSession.DrawImage(extendMesh);
                }
            };

            this.CanvasControl.Draw += (sender, args) =>
            {
                if (base.IsEnabled == false)
                {
                    return;
                }
                if (this.array is null)
                {
                    return;
                }

                // Background
                args.DrawingSession.DrawImage(this.GrayAndWhiteBackground);

                // LinearGradient
                this.Size.DrawLinearGradient(args.DrawingSession, this.CanvasControl, this.array);

                // Lines
                this.Size.DrawLines(args.DrawingSession);

                // Nodes
                this.Size.DrawNodes(args.DrawingSession, this.Manager);
            };
        }
Example #19
0
        public void Draw(ICanvasResourceCreator rc, CanvasDrawingSession ds, double W, double H, float X = 0, float Y = 0)
        {
            if (this.Image != null)
            {
                CommandList = new CanvasCommandList(rc);
                r.Width     = W;
                r.Height    = H;

                using (var dds = CommandList.CreateDrawingSession())
                {
                    dds.FillRectangle(0, 0, (float)W, (float)H, lgb);
                    dds.DrawImage(this.Image, 0, 0, r, 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.DestinationIn);
                }
                ds.DrawImage(CommandList, X, Y);
            }
        }
Example #20
0
        public override void Draw(CanvasDrawingSession drawSession)
        {
            Direction aimDirection = CalculateAimDirection();
            int       assetIndex   = (int)aimDirection;

            if (reloading)
            {
            }
            else
            {
                if (assetIndex < aimingBitmaps.Count)
                {
                    drawSession.DrawImage(aimingBitmaps[assetIndex], position);
                }
            }
        }
Example #21
0
        // </SnippetBlurAmountWin2D>

        // <SnippetProcessFrameWin2D>
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
                    using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                    {
                        var gaussianBlurEffect = new GaussianBlurEffect
                        {
                            Source       = inputBitmap,
                            BlurAmount   = (float)BlurAmount,
                            Optimization = EffectOptimization.Speed
                        };

                        ds.DrawImage(gaussianBlurEffect);
                    }
        }
Example #22
0
        public static void Render()
        {
            using (CanvasDrawingSession ds = App.Model.SecondSourceRenderTarget.CreateDrawingSession())//新图片上画几何
            {
                ds.Clear(Colors.Transparent);
                ds.FillRectangle(0, 0, App.Model.Width, App.Model.Height, App.Setting.GradientBrush);

                if (App.Model.isAnimated == true)
                {
                    ds.DrawImage(App.Model.MaskRenderTarget, 0, 0, App.Model.MaskRenderTarget.Bounds, 1, CanvasImageInterpolation.Linear, CanvasComposite.DestinationIn);
                }
            }

            App.Model.isReRender = true; //重新渲染
            App.Model.Refresh++;         //画布刷新
        }
        /// <summary>
        /// Draw render.
        /// </summary>
        public void DrawRender(CanvasDrawingSession drawingSession)
        {
            ICanvasImage canvasImage = LayerBase.Render(LayerManager.CanvasDevice, LayerManager.RootLayerage);

            if (canvasImage is null)
            {
                return;
            }

            drawingSession.DrawImage(new Transform2DEffect
            {
                InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
                TransformMatrix   = this.CanvasTransformer.GetMatrix(),
                Source            = canvasImage
            });
        }
Example #24
0
        //初始化液化渲染目标
        public static void InitializeLiquify()
        {
            //特效渲染目标
            using (CanvasDrawingSession ds = App.Model.SecondSourceRenderTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);
                //获得当前图层的渲染目标
                ds.DrawImage(App.Model.CurrentRenderTarget);
            }

            //下层清空为蓝色
            using (CanvasDrawingSession ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
            {
                ds.Clear(App.Setting.LiquifyColor);
            }
        }
Example #25
0
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
                    using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                    {
                        ColorMatrixEffect colorMatrixEffect = new ColorMatrixEffect
                        {
                            Source = inputBitmap
                        };

                        colorMatrixEffect.ColorMatrix = ColorMatrix;

                        ds.DrawImage(colorMatrixEffect);
                    }
        }
Example #26
0
        private void DoEffect(CanvasDrawingSession ds, Size size, float amount, Windows.UI.Color glowColor, Windows.UI.Color fillColor, double expandAmount)
        {
            var offset = (float)expandAmount / 2;

            using (var cl = new CanvasCommandList(ds))
            {
                using (var clds = cl.CreateDrawingSession())
                {
                    clds.FillRectangle(0, 0, (float)size.Width, (float)size.Height, glowColor);
                }

                _eg.Setup(cl, amount, GlowColor);
                ds.DrawImage(_eg.Output, offset, offset);
                ds.FillRectangle(offset, offset, (float)size.Width, (float)size.Height, fillColor);
            }
        }
Example #27
0
        public static void Apply()
        {
            //Undo:撤销
            Undo undo = new Undo();

            undo.TargeInstantiation(App.Model.Index, App.Model.CurrentRenderTarget);
            App.UndoAdd(undo);

            Layer l = App.Model.Layers[App.Model.Index];

            using (CanvasDrawingSession ds = l.CanvasRenderTarget.CreateDrawingSession())
            {
                ds.DrawImage(App.Model.SecondSourceRenderTarget);
            }
            l.SetWriteableBitmap(App.Model.VirtualControl);//刷新缩略图}
        }
        static void DrawSecondsText(CanvasDrawingSession ds, Vector2 pos, int seconds)
        {
            // The text is drawn via a command list so we can use DrawImage to specify a difference CanvasComposite mode.
            using (var cl = new CanvasCommandList(ds))
            {
                using (var clds = cl.CreateDrawingSession())
                {
                    clds.DrawText(seconds.ToString(), Vector2.Zero, Colors.White, textFormat);
                }

                Rect textBounds = cl.GetBounds(ds);
                var offset = new Vector2((float)textBounds.Left, (float)textBounds.Top);

                ds.DrawImage(cl, pos + offset, cl.GetBounds(ds), 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.MaskInvert);
            }
        }
Example #29
0
        public void Render(CanvasDrawingSession drawingSession, Size canvasSize)
        {
            var viewportWidth  = RenderTargetViewport.Width;
            var viewportHeight = RenderTargetViewport.Height;

            if (RenderTarget == null || viewportWidth <= 0 || viewportHeight <= 0)
            {
                return;
            }

            lock (RenderTargetLock)
            {
                var destinationRect = ComputeBestFittingSize(canvasSize, RenderTargetAspectRatio);
                drawingSession.DrawImage(RenderTarget, destinationRect, RenderTargetViewport);
            }
        }
        /// <summary>
        /// Save image with Ink
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ButtonSaveImage_ClickAsync(object sender, RoutedEventArgs e)
        {
            // The original bitmap from the screen, missing the ink.
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap();
            await renderBitmap.RenderAsync(this.gridInk);

            Size bitmapSizeAt96Dpi = new Size(renderBitmap.PixelWidth, renderBitmap.PixelHeight);

            IBuffer renderBitmapPixels = await renderBitmap.GetPixelsAsync();

            CanvasDevice win2DDevice = CanvasDevice.GetSharedDevice();

            DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();

            using (CanvasRenderTarget win2DTarget = new CanvasRenderTarget(win2DDevice, (float)this.gridInk.ActualWidth, (float)this.gridInk.ActualHeight, 96.0f))
            {
                using (CanvasDrawingSession win2dSession = win2DTarget.CreateDrawingSession())
                {
                    using (CanvasBitmap win2dRenderedBitmap = CanvasBitmap.CreateFromBytes(win2DDevice, renderBitmapPixels, (int)bitmapSizeAt96Dpi.Width, (int)bitmapSizeAt96Dpi.Height, DirectXPixelFormat.B8G8R8A8UIntNormalized, 96.0f))
                    {
                        win2dSession.DrawImage(win2dRenderedBitmap, new Rect(0, 0, win2DTarget.SizeInPixels.Width, win2DTarget.SizeInPixels.Height), new Rect(0, 0, bitmapSizeAt96Dpi.Width, bitmapSizeAt96Dpi.Height));
                    }
                    win2dSession.Units = CanvasUnits.Pixels;
                    win2dSession.DrawInk(this.inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
                }

                //Get file and save
                FileSavePicker picker = new FileSavePicker();
                picker.FileTypeChoices.Add("JPEG Image", new string[] { ".jpg" });
                StorageFile file = await picker.PickSaveFileAsync();

                if (file != null)
                {
                    using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);

                        encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                             BitmapAlphaMode.Ignore,
                                             (uint)this.gridInk.ActualWidth, (uint)this.gridInk.ActualHeight,
                                             96, 96, win2DTarget.GetPixelBytes());

                        await encoder.FlushAsync();
                    }
                }
            }
        }