簡體   English   中英

Windows API代碼包 - ShellFile不生成PDF位圖

[英]Windows API Code Pack - ShellFile not generating PDF bitmap

使用以前堆棧溢出問題中的代碼:

System.Drawing.Bitmap image;
ShellFile f = ShellFile.FromFilePath(fileLocation);
image = f.Thumbnail.ExtraLargeBitmap;
image.Save(tempfile, ImageFormat.Png);

我正在嘗試使用窗口API來獲取PDF的縮略圖

我被認為這會生成一個類似於PDF文檔第一頁的圖像文件。

但事實是,它看起來並不像那樣,只是看起來像PDF圖標。

在實際按預期工作之前,是否有任何我需要的東西?

PDF文件與adobe reader正確關聯。

當在Windows Explorer中瀏覽目錄, 看到與文件相關的縮略圖。

我應該注意,代碼實際上在處理Excel和Word文檔時正確提取縮略圖。

編輯(參考):

您需要指定您想要縮略圖,而不是圖標(默認)。 將您的代碼更改為:

System.Drawing.Bitmap image;
ShellFile f = ShellFile.FromFilePath(fileLocation);

//force the actual thumbnail, not the icon
f.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;

image = f.Thumbnail.ExtraLargeBitmap;
image.Save(tempfile, ImageFormat.Png);

問題是因為您沒有選擇要從中創建縮略圖的活動框架。

我無法在當前的機器上驗證它,因為我沒有Windows API,但是它給你標准的PDF縮略圖,因為在你的代碼中你沒有指定用於縮略圖的頁面。

嘗試做這樣的事情:

        Image image = new Image();
        //Load image here
        int frameindex = 1; // Page number you want to use for thumbnail
        Guid guide = image.FrameDimensionsList[0];
        FrameDimension fDimension = new FrameDimension(guide);
        image.SelectActiveFrame(fDimension, frameindex);
        //Then go on to extract your thumbnail

我無法讓ExtraLargeBitmap適用於PDF文件,但所有其他尺寸(大,中,小)都能正常工作。

Dim MyShellFile As ShellFile = ShellFile.FromFilePath(fi.FullName)
Dim MyThumbNail As Image
MyShellFile.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly
MyThumbNail = MyShellFile.Thumbnail.LargeBitmap
Me.PictureBox2.Image = MyThumbNail

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM