使用File.Copy命令后创建文件的缩略图 [英] Create a thumbnail of a file after using the File.Copy Command

查看:58
本文介绍了使用File.Copy命令后创建文件的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用File.Copy命令首先将文件复制到另一个目录,然后我想获取该文件的缩略图,如Windows资源管理器中所示。要获取文件的缩略图图像,我使用以下命令

I am using the File.Copy command to first copy a file to another directory and then I want to get the thumbnail of the file as shown in Windows Explorer. To get the thumbnail image of the file I am using the following command

shellFile.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;

位图shThumb = shellFile.Thumbnail.ExtraLargeBitmap;

Bitmap shThumb= shellFile.Thumbnail.ExtraLargeBitmap;

shThumb.Save(" D:\\ MyThumb.jpg",ImageFormat.Jpeg);

shThumb.Save("D:\\MyThumb.jpg",ImageFormat.Jpeg);




当使用上面的代码行而不使用File.Copy()时,它可以工作精细。但是,如果我首先将文件复制到另一个目录,然后想要在新文件上使用上面的代码,它就会挂起。它会挂起,直到我手动转到Windows资源管理器
中的文件并单击它一次。然后代码工作。

When just using the code lines above without using File.Copy(), it works fine. But if I first copy the file to another directory and then want to use the code above on the new file, it hangs. And it hangs until I go manually to the file in Windows Explorer and click once on it. Then the code works.

那么有没有办法在使用File.Copy之后运行代码而无需手动点击文件?

So is there a way to get the code run after using File.Copy without to click manually on the file?

推荐答案

我怀疑问题是在您点击文件之前它不会生成缩略图。它在file.copy之前工作的原因是你已经导航到该文件。事实上,这是在

SO
帖子中记录的。几年前。 

I suspect the issue is that it doesn't generate the thumbnail until you click on the file. The reason it works prior to your file.copy is that you've already navigated to the file. In fact this is documented in a SO post from a few years ago. 

不幸的是,您尝试使用第三方库提供的类。在这种情况下,库是由MS的一些人提供的,但这些论坛仍然不适合支持这个。我建议直接使用Shell接口
,如SO帖子中所述。它看起来更可靠。

Unfortunately you're trying to use a class that is provided by a third party library. In this case the library is provided by some folks from MS but these forums still aren't the appropriate place for support for this. I'd recommend that use the Shell interface directly as documented in the SO post. It seems to be more reliable.


这篇关于使用File.Copy命令后创建文件的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆