在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);
}
}
}
}
你爲什麼將它們轉換爲圖像? Pdf是一種可縮放的矢量格式。 – WiredPrairie
我需要使用它,將它們顯示在winrt應用程序中並允許縮放。如果我保留PDF格式,處理和直接在應用程序中顯示更加困難。 – GermanSniper
通過將其轉換爲高分辨率位圖,您的應用程序可能會消耗大量的內存,這可能會導致應用程序被終止。 – WiredPrairie