c# – 在Windows XPVista上获取包括SolidWorks在内的任何文件的缩略图

c# – 在Windows XPVista上获取包括SolidWorks在内的任何文件的缩略图,第1张

概述每个安装的 *** 作系统中都有很多内置的ThumbnailProviders.由于这些提供程序 Windows可以显示许多文件的缩略图.例如,Windows资源管理器可以显示* .jpg文件的内容,但也可以显示Solidworks * .sldprt文件的内容(如果安装了SolidWorks). 但有没有办法获得这些缩略图?我曾尝试使用Windows API CodecPack来管理它,但我只在Wind 每个安装的 *** 作系统中都有很多内置的thumbnailProvIDers.由于这些提供程序 Windows可以显示许多文件的缩略图.例如,windows资源管理器可以显示* .jpg文件的内容,但也可以显示SolIDworks * .sldprt文件的内容(如果安装了SolIDWorks).

但有没有办法获得这些缩略图?我曾尝试使用windows API CodecPack来管理它,但我只在windows 7上成功.

Shellfile shellfile = Shellfile.FromfilePath(filePath);                Bitmap shellThumb = shellfile.thumbnail.Bitmap;

问题是:在windows XP / Vista上是否有任何其他可用的方法来获取已注册缩略图提供程序的任何文件的缩略图?我真的很绝望……

解决方法 有几种方法:

1)使用库OpenMCDF.
SolIDworks文件是Compound document,因此访问其内容 – 正在解析文件.

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作为控件添加并放置到Form中.

OpenfileDialog dialog = new OpenfileDialog();        if (dialog.ShowDialog() == DialogResult.OK)        {            axEModelVIEwControl1.OpenDoc(dialog.filename.ToString(),false,true,"");        }

3)使用SWExplorer库(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)

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,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();        }
总结

以上是内存溢出为你收集整理的c# – 在Windows XP / Vista上获取包括SolidWorks在内的任何文件的缩略图全部内容,希望文章能够帮你解决c# – 在Windows XP / Vista上获取包括SolidWorks在内的任何文件的缩略图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1246505.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存