I have a WPF form that contains a WindowsFormsHost control.
This WindowsFormsHost control is added intentionally to add ActiveX/WinForms controls at the same time.
Eventually, I have to take a picture of the form that contains the WindowsFormsHost control, here is the problem.
I've found how to save wpf ( this way ) as jpg and winforms as jpg ( here ) too.
From WPF:
formGrid is base Grid in WPF form
RenderTargetBitmap rtb = new RenderTargetBitmap((int)formGrid.ActualWidth, (int)formGrid.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rtb.Render(formGrid);
JpegBitmapEncoder jpg = new JpegBitmapEncoder();
jpg.Frames.Add(BitmapFrame.Create(rtb));
using (Stream stm = File.Create(@"c:\testwpf.jpg"))
{
jpg.Save(stm);
}
From WinForms:
formhost is WindowsFormHost control
using (var bmp = new System.Drawing.Bitmap((int)formhost.Width, (int)formhost.Height))
{
formhost.Panel.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(@"c:\testwinform.jpg")
}
What I want is to mix/merge, if it were possible, the result of getting both renderings into one single image.
PD: I tried to create a BitmapSource from Bitmap and add it to the JpegBitmapEncoder but I got no successful result.