I want to use WPF to realize the function of obtaining thumbnails of video files and display them in ListView, but after searching, I found that everyone uses FFmpeg to intercept. I feel very bad. First of all, FFmpeg is very large, and it is very inconvenient to integrate into the software. Furthermore, it is a command-line tool. After executing it, it generates a picture and then reads it again. It is quite irritating, so I wonder if there are other better and easier methods?
Windows Explorer itself can obtain thumbnails of video files without relying on any third-party components. Can it call system functions? Finally, the research found that it can be realized through the API of the system.
Requires NuGet to reference a library WindowsAPICodePack-Shell
Then easily get it done in one sentence:
using Microsoft.WindowsAPICodePack.Shell;
using System.Drawing;
public static class ImageTool
{
public static Bitmap GetThumbnailByPath(string filePath)
{
ShellFile shellFile = ShellFile.FromFilePath(filePath);
Bitmap thumbnail = shellFile.Thumbnail.ExtraLargeBitmap;
return thumbnail;
}
}
It's very simple, a Bitmap is returned directly, and then you can do whatever you want with the bitmap.