Instead of a System.Drawing.Bitmap
you have to put a WPF System.Windows.Controls.Image
control into the BlockUIContainer. First, you have to convert your Bitmap
into something that can by used as the Source
of an Image
e.g. a WPF BitmapImage
. Then you would create a new Image
control and add that to your document:
System.Drawing.Bitmap bitmap = ...
var bitmapImage = new BitmapImage();
using (var memoryStream = new MemoryStream())
{
bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
}
var image = new Image
{
Source = bitmapImage,
Stretch = Stretch.None
};
doc.Blocks.Add(new BlockUIContainer(image));