I'm trying to get a high resolution icon or thumbnail in Windows given a full path to that file. Doesn't need to be a thumbnail —?a good looking Icon will be great. I Don't care if it's an HICON
or an HBITMAP
: I'm going to put it in a GDI+ object and render it into a device context.
I've tried using SHGetFileInfo
(with various variations on flags), but never get more than a ~32x32 icon back, which scales horribly to the 128 pixels or so that I need.
if (!SHGetFileInfoW(path, 0, &fi, sizeof(fi),
SHGFI_ICON | SHGFI_ICONLARGE | SHGFI_TYPENAME))
return GetLastError();
// fi.hIcon is a valid icon here, but it's horrible quality with
// a black mask on it. I want higher quality, and dare I dream of
// alpha channel? Mask is acceptable, i suppose.
SHGetFileInfo
returns ""
when I call with SHGFI_ICONLOCATION
(which appears to be a known problem with that API).
I've also tried using SHCreateItemFromParsingName
name with the intention of getting IThumbnailProvider
, but BindToHandler
always returns E_NOTIMPL
for BHID_ThumbnailHandler
...
IShellItem *psi;
hr = SHCreateItemFromParsingName(path, NULL, IID_PPV_ARGS(&psi));
if (SUCCEEDED(hr))
{
IThumbnailProvider *pThumbProvider;
hr = psi->BindToHandler(NULL, BHID_ThumbnailHandler,
IID_PPV_ARGS(&pThumbProvider));
if (SUCCEEDED(hr))
{
// never get here because hr == E_NOTIMPL !!!
I've actually run the Microsoft Thumbnail Providers Sample and found that it suffers from the same problem with BindToInterface
.
So, any suggestions on what else I could try? I just want something picture-y that more or less represents this file at, say, at least 100px size — just anything better than 32x32 ...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…