本文介绍了获取使用的VisualBrush一个WPF区System.Drawing.Bitmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 问题的关键是,我需要转换为System.Drawing.Bitmap(.Net框架2.0)得到一个WPF网格其内容的单个帧。The point is, that I need to convert to a System.Drawing.Bitmap (.Net Framework 2.0) to get a single frame of an WPF Grid with its content.我读的VisualBrush 和 DrawingBrush ,但我不能想象它应该如何工作。I read about VisualBrush and DrawingBrush but I cannot imagine how it should work.我可以在任何WPF 的BitmapSource 转换成我的系统。 Drawing.Bitmap 成功。但如何获得的BitmapSource 从我的网格?I can convert any WPF BitmapSource into my System.Drawing.Bitmap successfully. But how to receive the BitmapSource from my Grid?感谢推荐答案要转换视觉到的BitmapSource 您可以使用 RenderTargetBitmap 的VisualBrush 和 DrawingVisual :To convert a Visual to BitmapSource you can use RenderTargetBitmap, VisualBrush and DrawingVisual:public BitmapSource ConvertToBitmapSource(UIElement element){ var target = new RenderTargetBitmap((int)(element.RenderSize.Width), (int)(element.RenderSize.Height), 96, 96, PixelFormats.Pbgra32); var brush = new VisualBrush(element); var visual = new DrawingVisual(); var drawingContext = visual.RenderOpen(); drawingContext.DrawRectangle(brush, null, new Rect(new Point(0, 0), new Point(element.RenderSize.Width, element.RenderSize.Height))); drawingContext.Close(); target.Render(visual); return target;} 这篇关于获取使用的VisualBrush一个WPF区System.Drawing.Bitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 07:06