问题
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