Get images from DrawingGroup

别来无恙 提交于 2020-01-23 01:40:06

问题


Maybe it's a stupid question, but I have some problems with finding the proper answer:S

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.


回答1:


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;

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);


来源:https://stackoverflow.com/questions/14267228/get-images-from-drawinggroup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!