2015-06-02 110 views
0

在WinRt應用程序中我想顯示pdf內容。爲此,我將所有的PDF頁面轉換爲圖像。但質量非常糟糕。同樣在縮放之後,它變得更多bader。WinRt將PDF轉換爲圖像提高圖像質量

我該如何提高質量!?可以使用編碼器?或者我需要更高的Widht/Hight值?

  StorageFile pdfFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName); 

      //Load Pdf File 
      pdfDocument = await PdfDocument.LoadFromFileAsync(pdfFile); 

      if (pdfDocument != null && pdfDocument.PageCount > 0) { 

       //Get Pdf page 
       for (int pageIndex = 0; pageIndex < pdfDocument.PageCount; pageIndex++) { 

        var pdfPage = pdfDocument.GetPage((uint)pageIndex); 

        if (pdfPage != null) { 
         // next, generate a bitmap of the page 
         StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder; 
         StorageFile pngFile = await tempFolder.CreateFileAsync(Guid.NewGuid().ToString() + ".png", CreationCollisionOption.ReplaceExisting); 

         if (pngFile != null) { 
          IRandomAccessStream randomStream = await pngFile.OpenAsync(FileAccessMode.ReadWrite); 

          PdfPageRenderOptions pdfPageRenderOptions = new PdfPageRenderOptions(); 
          pdfPageRenderOptions.IsIgnoringHighContrast = false; 

          PdfPageDimensions rotation = pdfPage.Dimensions; 
          Size pdfPageSize = pdfPage.Size; 
          if (pdfPageSize.Height > 1000) { 
           pdfPageRenderOptions.DestinationHeight = (uint)(pdfPageSize.Height * 0.85); 
          } 
          else if (pdfPageSize.Width > 1000) { 
           pdfPageRenderOptions.DestinationWidth = (uint)(pdfPageSize.Width * 1.25); 
          } 

          await pdfPage.RenderToStreamAsync(randomStream, pdfPageRenderOptions); 
          await randomStream.FlushAsync(); 

          randomStream.Dispose(); 
          pdfPage.Dispose(); 

          PdfPagePath = pngFile.Path; 
          PdfPagesPathCollection.Add(pngFile.Path); 

         } 
        } 
       } 
      } 
+0

你爲什麼將它們轉換爲圖像? Pdf是一種可縮放的矢量格式。 – WiredPrairie

+0

我需要使用它,將它們顯示在winrt應用程序中並允許縮放。如果我保留PDF格式,處理和直接在應用程序中顯示更加困難。 – GermanSniper

+0

通過將其轉換爲高分辨率位圖,您的應用程序可能會消耗大量的內存,這可能會導致應用程序被終止。 – WiredPrairie

回答

0

PDF格式允許無限完美縮放,因爲它是一種基於矢量的格式。當您將頁面轉換爲圖像時,受限於該轉換的分辨率,縮放將顯示像素。

解決方案是以更高的分辨率和比例渲染到顯示器,它會給你一些縮放範圍,但它仍然會達到極限。在其他平臺上,只需渲染所需的縮放級別即可完成該部分,但我認爲這不可能使用此PdfDocument

+0

是的,我試圖用位圖轉換,但圖像很大。現在我以更高的分辨率拍攝PDF快照,並將其縮小爲普通視圖。在縮放模式下,質量更好,因爲信號源具有更高的分辨率.... – GermanSniper