如何解决如何通过python从windows缓存中获取文件缩略图?
目标是在尽可能短的时间内从 Windows 上的选定文件夹中获取文件缩略图。
Imagemagick 和其他工具每次都打开文件,因此它们可能不是最有效的。 Windows 的内置机制可以将缩略图缓存在缓存中,这在理论上可以显着提升速度。
从How to get thumbnail of file using the Windows API? (answer) 开始,方法已经很清楚了,但是问题很多:
-
IThumbnailProvider 和 IThumbnailCache 未在以下位置找到:
- ctypes.windll.shell32(只有函数,貌似没有简单的获取接口的方法)
- win32com.shell.shell (PyWin32)
-
IID_IThumbnailProvider 和 IShellItemImageFactory 到 SHCreateItemFromParsingName 和 IID:
-
在 win32com.shell.shell 中找不到该 IID,因此它们是手动提供的。
-
IThumbnailProvider,IShellItem::BindToHandler method:已修复,但现在错误如下:
# str(shell.IID_IShellItem) == '{43826D1E-E718-42EE-BC55-A1E261C37BFE}' # str(shell.BHID_ThumbnailHandler) == '{7B2E650A-8E20-4F4A-B09E-6597AFC72FB0}' item = shell.SHCreateItemFromParsingName(r'd:\some.png',None,str(shell.IID_IShellItem)) # str() is works IID_IThumbnailProvider = '{e357fccd-a995-4576-b01f-234630154e96}' provider = item.BindToHandler(None,shell.BHID_ThumbnailHandler,IID_IThumbnailProvider) # error > TypeError: 'There is no interface object registered that supports this IID'
-
IShellItemImageFactory:怀疑 IID 的用法有误,但从下面的 answer 应该可以:
IID_IShellItemImageFactory = '{bcc18b79-ba16-442f-80c4-8a59c30c463b}' item = shell.SHCreateItemFromParsingName(r'd:\some.png',IID_IShellItemImageFactory) # error > TypeError: 'There is no interface object registered that supports this IID'
-
在不学习整个 winapi 的情况下了解如何在所有这些中游泳会很棒..
提前致谢。
Windows 10 (20H2)、Python 3.9.5、PyWin32 301
更新:找到有关 PyWin32 (pythoncom.CoCreateInstance can't create IZoneIdentifier; the interface is missing from registry too despite being documented in MSDN) 的答案。简而言之,这些接口没有实现。检查者:
> import pythoncom
> pythoncom.InterfaceNames
所以..还有2个问题。是否有任何选项可以在不使用 PyWin32 的情况下获得缩略图?例如,通过 ctypes。以及如何?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。