A couple of blogs below introduce how to get thumbnail of a document.
Document Thumbnails and Button Icons
In this post, we use one more way which takes advantage of Metafile of System.Drawing.Imaging.
The code assumes there is one picturebox and one button in one Windows form application. When the button clicks, a file dialog will ask you to select an Inventor file, and the picturebox will display its thumbnail.
using Inventor;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using stdole;
// callback function for GetThumbnailImageAbort
bool ThumbnailCallback()
{
return false;
}
// button event to get thumbnail
private void btnOpen_Click(object sender, EventArgs e)
{
OpenFileDialog oFDlg = new OpenFileDialog();
if (oFDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ApprenticeServerComponent oApprenticeApp =
new ApprenticeServerComponent();
ApprenticeServerDocument oDoc;
try
{
oDoc = oApprenticeApp.Open(oFDlg.FileName);
}
catch (Exception ex)
{
MessageBox.Show("cannot open the file!");
return;
}
stdole.IPictureDisp oPD = oDoc.Thumbnail;
Metafile oMF = new Metafile(
new IntPtr(oPD.Handle),
new WmfPlaceableFileHeader());
Image.GetThumbnailImageAbort oCallBack =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
pictureBox1.Image =
oMF.GetThumbnailImage(pictureBox1.Width,
pictureBox1.Height,
oCallBack, IntPtr.Zero);
}