I am making C# application that is supposed to extract images from doc file and show all extracted images in Pictureboxes. I have following codes:
WRONG SOLUTION
using Microsoft.Office.Interop.Word;
public IDataObject ImageData { get; private set; }
public List<Image> GetImages(Document doc)
{
List<Image> image = new List<Image>();
foreach (InlineShape shape in doc.InlineShapes)
{
shape.Range.Select();
if (shape.Type == WdInlineShapeType.wdInlineShapePicture)
{
doc.ActiveWindow.Selection.Range.CopyAsPicture();
ImageData = Clipboard.GetDataObject();
Image img = (Image)ImageData.GetData(DataFormats.Bitmap);
image.Add(img);
/*
bmp.Save("C:\\Users\\Akshay\\Pictures\\bitmaps\\test" + i.ToString() + ".bmp");
*/
}
}
return image;
}
The problem is that if I insert images on page 2 in my doc file then img becomes null. While if i insert all images in page 1 then it works perfectly fine. I am curious to know what is the mistake in above codes. Any help will be highly appreciated.