As per project requirement we need to convert images from word document into bitmap object. To achieve this we tried to convert inlineshape object from Microsoft.Office.Inte
There's two Clipboard.
Usually we'd use System.Windows.Forms.Clipboard
, but it sucks.
Use System.Windows.Clipboard
instead, just add PresentationCore to your references.
(in my case, C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\PresentationCore.dll)
Try this.
foreach (InlineShape shape in d.InlineShapes)
{
if (shape != null)
{
shape.Range.Select();
d.ActiveWindow.Selection.Copy();
Bitmap bitmap = new Bitmap(Clipboard.GetImage());
}
}
Resolved in this post: https://stackoverflow.com/a/7937590/1071212 It's a problem with STAThread:
Thread thread = new Thread([Method]);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();