问题描述
有很多的每一个安装的操作系统中内置的ThumbnailProviders。由于这些供应商的Windows能够显示的多个文件的缩略图。例如Windows资源管理器可以显示的* .jpg文件的内容,但是从SolidWorks * .SLDPRT文件了(如果安装有SolidWorks)。
There is a lot of build-in ThumbnailProviders inside every installed OS. Due to these providers Windows is able to show Thumbnail of many files. For example Windows Explorer can show content of *.jpg files, but from Solidworks *.sldprt files too (If SolidWorks is installed).
但是,有没有什么办法让这些缩略图?从来就试图管理这个使用Windows API codecPack,但我成功了仅在Windows 7。
But is there any way to get these thumbnails? I´ve tried to manage this using Windows API CodecPack, but I succeeded only on Windows 7.
ShellFile shellFile = ShellFile.FromFilePath(filePath);
Bitmap shellThumb = shellFile.Thumbnail.Bitmap;
问题是:是否有任何其他可用的办法让在Windows XP / Vista中注册的缩略图提供任何文件的缩略图? I'm真的绝望了......
Question is: is there any other usable way to get Thumbnail of any file with registered Thumbnail provider on Windows XP/Vista? I´m really desperate...
推荐答案
有几种方式:
1)随着库 OpenMCDF 。Solidworks的文件是复合文档,以便访问其内容 - 被解析的文件
1) With library OpenMCDF.Solidworks file is Compound document so access to its content - is parsing the file.
OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = Application.StartupPath;
if (dialog.ShowDialog() == DialogResult.OK)
{
string STORAGE_NAME = dialog.FileName.ToString();
CompoundFile cf = new CompoundFile(STORAGE_NAME);
CFStream st = cf.RootStorage.GetStream("PreviewPNG");
byte[] buffer = st.GetData();
var ms = new MemoryStream(buffer.ToArray());
pictureBox1.Image = Image.FromStream(ms);
}
2)随着库EModelView.dll添加作为对照,并放置到窗体。
2) With library EModelView.dll to be added as a control and placed to the Form.
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
axEModelViewControl1.OpenDoc(dialog.FileName.ToString(), false, false, true, "");
}
3)随着SWExplorer库(WPF previewFlowControl)
3) With SWExplorer library (wpfPreviewFlowControl)
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
string sDocFileName = dialog.FileName.ToString();
wpfThumbnailCreator pvf;
pvf = new wpfThumbnailCreator();
System.Drawing.Size size = new Size();
size.Width = 200;
size.Height = 200;
pvf.DesiredSize = size;
System.Drawing.Bitmap pic = pvf.GetThumbNail(sDocFileName);
pictureBox1.Image = pic;
}
3)在库文件管理器(SolidWorks.Interop.swdocumentmgr)
3) With library Document Manager (SolidWorks.Interop.swdocumentmgr)
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
string sDocFileName = dialog.FileName.ToString();
SwDMClassFactory swClassFact = default(SwDMClassFactory);
SwDMApplication swDocMgr = default(SwDMApplication);
SwDMDocument swDoc = default(SwDMDocument);
SwDMConfigurationMgr swCfgMgr = default(SwDMConfigurationMgr);
string[] vCfgNameArr = null;
SwDMConfiguration7 swCfg = default(SwDMConfiguration7);
IPictureDisp pPreview = default(IPictureDisp);
SwDmDocumentType nDocType = 0;
SwDmDocumentOpenError nRetVal = 0;
SwDmPreviewError nRetVal2 = 0;
Image image = default(Image);
//Access to interface
swClassFact = new SwDMClassFactory();
swDocMgr = (SwDMApplication)swClassFact.GetApplication("Post your code here");
swDoc = (SwDMDocument)swDocMgr.GetDocument(sDocFileName, nDocType, false, out nRetVal);
Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone == nRetVal);
swCfgMgr = swDoc.ConfigurationManager;
pathLabel.Text = "Path to file: " + swDoc.FullName;
configLabel.Text = "Active config: " + swCfgMgr.GetActiveConfigurationName();
vCfgNameArr = (string[])swCfgMgr.GetConfigurationNames();
foreach (string vCfgName in vCfgNameArr)
{
//get preview
swCfg = (SwDMConfiguration7)swCfgMgr.GetConfigurationByName(vCfgName);
pPreview = (IPictureDisp)swCfg.GetPreviewPNGBitmap(out nRetVal2);
image = Support.IPictureDispToImage(pPreview);
//insert to picturebox
pictureBox1.BackgroundImage = image;
}
swDoc.CloseDoc();
}
这篇关于获取任何文件的缩略图,不仅图像文件,在Windows XP / Vista的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!