2015-06-02 36 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