但有没有办法获得这些缩略图?我曾尝试使用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在内的任何文件的缩略图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)