I’m using WindowsAPICodePack, getting ShellFile’s Thumbnail’s. But some of those which look like the generic icons – have a black background. I therefore make it a Bitmap and set Black as transparent.
The problem is that when it’s a thumbnail of a picture – it shouldn’t do it. How can I tell a real thumbnail from an “icon”?
My code:
ShellFile sf = ShellFile.FromFilePath(path);
Bitmap bm = sf.Thumbnail.MediumBitmap;
bm.MakeTransparent(Color.Black);
Thanks
You can approach this problem from another angle. It is possible to force the ShellFile.Thumbnail to only extract the thumbnail picture if it exists or to force it to extract the associated application icon.
So your code would look something like this:
Bitmap bm;
using (ShellFile shellFile = ShellFile.FromFilePath(filePath))
{
ShellThumbnail thumbnail = shellFile.Thumbnail;
thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
try
{
bm = thumbnail.MediumBitmap;
}
catch // errors can occur with windows api calls so just skip
{
bm = null;
}
if (bm == null)
{
thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
bm = thumbnail.MediumBitmap;
// make icon transparent
bm.MakeTransparent(Color.Black);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With