C#Shell缩略图在ppt文件上无法正常工作

C#Shell缩略图在ppt文件上无法正常工作,c#,shell,thumbnails,C#,Shell,Thumbnails,我有以下函数来获取文件的位图图像 public static BitmapImage GetThumbnail(string filePath) { ShellFile shellFile = ShellFile.FromFilePath(filePath); BitmapSource shellThumb = shellFile.Thumbnail.ExtraLargeBitmapSource; BitmapImage bImg = new BitmapImage()

我有以下函数来获取文件的
位图图像

public static BitmapImage GetThumbnail(string filePath)
{
    ShellFile shellFile = ShellFile.FromFilePath(filePath);
    BitmapSource shellThumb = shellFile.Thumbnail.ExtraLargeBitmapSource;

    BitmapImage bImg = new BitmapImage();
    PngBitmapEncoder encoder = new PngBitmapEncoder();
    MemoryStream memoryStream = new MemoryStream();
    encoder.Frames.Add(BitmapFrame.Create(shellThumb));
    encoder.Save(memoryStream);
    bImg.BeginInit();
    bImg.StreamSource = memoryStream;
    bImg.EndInit();

    return bImg;
}
当我得到视频的缩略图时,它总是起作用。
当我得到演示文稿(pptx)缩略图时,它不能正常工作(我不知道它什么时候工作,什么时候不工作)

例如,我在目录中有两个文件:

在我的程序中是这样的-1正常,1不正常(有时两者都正常,有时两者都不正常):

如果你能告诉我问题出在哪里,或者给我另一种不会失败的方法,我将不胜感激

p.s.

我想提醒大家,对于视频文件,它可以100%正常工作(.mp3、.mp4、.wmv-这就是我测试的内容)

因为我想获得pptx缩略图,所以我想出了以下解决方案:
1.我使用DotNetZip提取了缩略图
2.我得到了位于docProps目录中的缩略图
3.我将缩略图提取到
memoryStream

4.我将
内存流
转换为
位图图像
,并将其返回

代码如下:

public static BitmapImage GetPPTXThumbnail(string filePath)
{
    using (ZipFile zip = ZipFile.Read(filePath))
    {
        ZipEntry e = zip["docProps/thumbnail.jpeg"];

        BitmapImage bImg = new BitmapImage();
        MemoryStream memoryStream = new MemoryStream();
        bImg.BeginInit();
        e.Extract(memoryStream);
        memoryStream.Seek(0, SeekOrigin.Begin);
        bImg.StreamSource = memoryStream;
        bImg.EndInit();

        return bImg;
    }
}
此解决方案不能失败,此解决方案仅用于获取PPTX缩略图,我假设它适用于所有office xml文件,如docx、xlsx等