How to extract file icon/thumbnail images from Windows Explorer?

26 vues (au cours des 30 derniers jours)
DDC
DDC le 22 Août 2024
Réponse apportée : DDC le 1 Sep 2024
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?

Réponse acceptée

DDC
DDC le 1 Sep 2024
I found an alternate solution. Since my original post I learned that the images contained in the text files in question (from a 3rd-party CAD software developer) are encoded as base64 text. I use fgetl(fid) to read the file line by line, searching for particular character strings that indicate the start of image data, in my case "Image64'/9j". The single quote following "Image64" indicates the start of the image data, and a second single quote indicates the end of image data. I use the strcat function to create a single long character array containing all characters between the two single quotes. For a character array named "image" the following code creates and saves a .jpeg image file named imagfile.jpeg:
model = matlab.net.base64decode(image);
fileName = 'imagefile.jpeg';
fidout = fopen(fileName, 'wb');
fwrite(fidout, model);
fclose(fidout);

Plus de réponses (1)

Madheswaran
Madheswaran le 23 Août 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:
  1. Call .NET from MATLAB - https://mathworks.com/help/matlab/call-net-from-matlab.html
  2. Make .NET assembly visible to MATLAB - https://mathworks.com/help/matlab/ref/net.addassembly.html
  3. ExtractAssociatedIcon - https://learn.microsoft.com/en-us/dotnet/api/system.drawing.icon.extractassociatedicon
  2 commentaires
DDC
DDC le 28 Août 2024
Thanks for the response. For this type of method to work, I really need large or extra-large icon mode. I now have more information about how image data is encoded in the files of greatest interest (created by a CAD program). Each 3D CAD model in a file is represented by an image which is encoded as base64. When converted to binary the base64 data represents a jpeg image. Given this new information, my desire is to extract the base64 image data for each separate model and convert it to jpeg format.
Madheswaran
Madheswaran le 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:
  1. For Preloading the Windows thumbnails - https://superuser.com/a/1290297/873074
  2. Capturning thumbnails from the cache - https://stackoverflow.com/q/14716939/9199105

Connectez-vous pour commenter.

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by