I’m trying to render an image from an unmanaged control on to a WPF window. So far I’m able to get a working graphics object (because I’m able to overlay image to the unmanaged control). What I’m hoping to do is the opposite, which is to capture image from graphics object and save as a imagesource for another control.
var graphics = Graphics.FromHwnd(hwndPtr);//From image unmanaged source
graphics.(??) // save to bitmap or any image format
If not possible to save an image with graphics object directly, would it be possible to get a raw reference to the image buffer of the graphics object? (For use with code like below)
var bmp = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(
hwntPtr,120,120,format,stride,0);
Thanks in Advance..
This is slightly modified code from an MSDN forum article but it should do the trick as far as getting a System.Drawing.Bitmap from a System.Drawing.Graphics object.
Original article