InkCanvas 保存图片

将  InkCanvas 里面的画面,保存为图片

* 该方法,保存的图片没有黑色的边框

 

private void ImageSave(InkCanvas inkCanvas, string _imageFile)
        {
            double width = inkCanvas.ActualWidth;
            double height = inkCanvas.ActualHeight;
            RenderTargetBitmap bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96, PixelFormats.Default);
            DrawingVisual dv = new DrawingVisual();
            using (DrawingContext dc = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(inkCanvas);
                dc.DrawRectangle(vb, null, new Rect(new System.Windows.Point(), new System.Windows.Size(width, height)));
            }
            bmpCopied.Render(dv);
            using (FileStream file = new FileStream(_imageFile,FileMode.Create, FileAccess.Write))
            {
                BmpBitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmpCopied));
                encoder.Save(file);
            }
        }

你可能感兴趣的:(String,File,null,vb)