How to extract file icon/thumbnail images from Windows Explorer?
Show older comments
I would like to extract the thumbnail images for files of various types that are used by Windows Explorer to represented the files in icon view mode. Any ideas on how to do this?
Accepted Answer
More Answers (1)
Madheswaran
on 23 Aug 2024
Hi,
I understand you would like to extract icons (or thumbnails) from the files in Windows File Explorer, however MATLAB doesn't natively provide any built-in functions for directly accessing these icons. To work around this, you can use a combination of MATLAB and .NET.
Here's a basic example of how you might achieve this using MATLAB with .NET:
% Ensure .NET is enabled in MATLAB
if ~usejava('jvm') || ~usejava('desktop')
error('MATLAB must be started with Java enabled to access .NET functionality.');
end
% Specify the file path for which you want to extract the icon
filePath = 'C:\path\to\your\file';
% Extract associated icon using .NET method
NET.addAssembly('System.Drawing');
icon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
bitmap = icon.ToBitmap();
% Save the image of icon
iconFilePath = [filePath, '_icon.png'];
bitmap.Save(iconFilePath, System.Drawing.Imaging.ImageFormat.Png);
% Display the image
iconImage = imread(iconFilePath);
imshow(iconImage);
The code above presents the results like this. Since I have used an image file in 'filePath', the image file icon appears as shown below:

The code provided above is designed to help you extract the icons associated with files as they appear in the 'small icons' view mode in Windows File Explorer. However, for certain types of files, such as multimedia or office documents, the thumbnail might change based on the file's content when viewed in 'large' or 'extra-large icons' mode. In these cases, I recommend exploring Windows native APIs, which might offer native support for retrieving content-specific thumbnails.
Refer to the following documentations for additional information:
- Call .NET from MATLAB - https://mathworks.com/help/matlab/call-net-from-matlab.html
- Make .NET assembly visible to MATLAB - https://mathworks.com/help/matlab/ref/net.addassembly.html
- ExtractAssociatedIcon - https://learn.microsoft.com/en-us/dotnet/api/system.drawing.icon.extractassociatedicon
2 Comments
DDC
on 28 Aug 2024
Madheswaran
on 1 Sep 2024
Like I mentioned in my answer, MATLAB does not natively support to capture the Windows file explorer thumbnails. I recomment exploring Windows native APIs for capturing content specific thumbnails. Also I have found resources from the web which might help you out:
- For Preloading the Windows thumbnails - https://superuser.com/a/1290297/873074
- Capturning thumbnails from the cache - https://stackoverflow.com/q/14716939/9199105
Categories
Find more on Call Web Services from MATLAB Using HTTP in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!