首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >获取任何文件的缩略图,包括Windows XP/Vista上的SolidWorks

获取任何文件的缩略图,包括Windows XP/Vista上的SolidWorks
EN

Stack Overflow用户
提问于 2012-08-10 00:39:26
回答 2查看 6.7K关注 0票数 7

在每个已安装的操作系统中都有大量的内置ThumbnailProviders。由于这些提供程序,Windows能够显示许多文件的缩略图。例如,Windows Explorer可以显示*.jpg文件的内容,但也可以显示来自Solidworks *.sldprt文件的内容(如果安装了SolidWorks )。

但是有没有办法弄到这些缩略图呢?我尝试过使用Windows API CodecPack来管理它,但我只在Windows7上成功了。

代码语言:javascript
运行
复制
ShellFile shellFile = ShellFile.FromFilePath(filePath);                
Bitmap shellThumb = shellFile.Thumbnail.Bitmap;

问题是:在Windows XP/Vista上,有没有其他可用的方法来获得任何文件的缩略图?我真的很绝望..。

EN

回答 2

Stack Overflow用户

发布于 2013-01-18 21:14:42

有几种方法:

1)使用库OpenMCDF。Solidworks文件是Compound document的,所以访问它的内容-是解析文件。

代码语言:javascript
运行
复制
 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添加为控件并放置到窗体中。

代码语言:javascript
运行
复制
    OpenFileDialog dialog = new OpenFileDialog();
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            axEModelViewControl1.OpenDoc(dialog.FileName.ToString(), false, false, true, "");
        }

3)使用SWExplorer库(wpfPreviewFlowControl)

代码语言:javascript
运行
复制
        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)

代码语言:javascript
运行
复制
         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();
        }
票数 5
EN

Stack Overflow用户

发布于 2013-01-08 03:42:37

可以使用非托管windows shell方法来获取缩略图。

Here is the code (not a small one)

但结果远非尽善尽美。

  • 调试非常困难,未指明的错误很常见,目标机器上必须有特定的文件读取器(例如pdf-
  • pdfs,我没有在SolidWorks)
  • can上尝试过)只在Windows
  • performance issue
  • thumbnails低质量下工作(尝试过pdf)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11888025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档