前端之家收集整理的这篇文章主要介绍了
InkCanvas 保存图片,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
301_0@将 InkCanvas 里面的画面,保存为
图片
@H_
301_0@* 该
方法,保存的
图片没有黑色的边框
@H_
301_0@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,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); } }
原文链接:https://www.f2er.com/vb/259965.html