问题描述
也许这是一个愚蠢的问题,但是我在寻找正确答案方面存在一些问题:S
Maybe it's a stupid question, but I have some problems with finding the proper answer:S
如何从DrawingGroup
获取作为Bitmap
或Image
(或类似名称)的帧?我实际上不知道该怎么咬.我试图在Internet上寻找它,但是在找到有用的东西时遇到了问题.
How to get frames as Bitmap
's or Image
's (or something similar) from DrawingGroup
? I don't actually know how to bite it. I tried to look for it in the Internet, but had problems with finding something useful.
推荐答案
如果需要将图像用作源. image%28v = vs.110%29.aspx"rel =" nofollow>图片控件,您只需将图形放入 DrawingImage :
If you need an image to be used as the Source of an Image control, you could simply put the drawing into a DrawingImage:
var drawing = ...
var drawingImage = new DrawingImage(drawing);
image.Source = drawingImage;
如果问题是关于创建 BitmapSource (即可以由 BitmapEncoder 通过 BitmapFrame ),则没有直接转换.您必须将图像放入中间Image控件中,然后将该控件呈现到 RenderTargetBitmap ,它是一个BitmapSource:
If the question is about creating a BitmapSource (i.e. something that can be encoded by a BitmapEncoder via a BitmapFrame), there is no direct conversion. You have to put the image into an intermediate Image control and render that control into a RenderTargetBitmap, which is a BitmapSource:
var drawing = ...
var drawingImage = new DrawingImage(drawing);
var image = new Image { Source = drawingImage };
var bitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32);
image.Arrange(new Rect(0, 0, bitmap.Width, bitmap.Height));
bitmap.Render(image);
这篇关于从DrawingGroup获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!