2

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.

Community
  • 1
  • 1
José Molero
  • 118
  • 10
  • "I got no successful result", what does that mean? Does the RenderTargetBitmap not show the WindowsFormsHost and its child? – Clemens Oct 24 '16 at 16:20
  • @Clemens exactly, RenderTargetBitmap only shows the WPF controls and WindowsFormsHost control is excluded from the picture. I only obtain data from WindowsFormsHost using DrawToBitmap function. – José Molero Oct 25 '16 at 06:29

0 Answers0