1

我正在尝试将 a 的页面PdfDocument作为一组BitmapImage's 保存到磁盘中,为此我使用了 WinRTXamlToolkit 提供的扩展名。

PdfPage page = pdfd.GetPage(0); // pdfd is a loaded PdfDocument
InMemoryRandomAccessStream str=new InMemoryRandomAccessStream();
await page.RenderToStreamAsync(str);
BitmapImage bmp = new BitmapImage();
await bmp.SetSourceAsync(str);

WriteableBitmap wb = await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bmp);

StorageFolder sfo;
sfo = await KnownFolders.DocumentsLibrary.CreateFolderAsync("PDFasBMP", CreationCollisionOption.OpenIfExists);

await WriteableBitmapSaveExtensions.SaveToFile(wb,sfo,"Yahooo.bmp");

输出“Yahooo.bmp”是一个不可读的 58 字节文件。我错过了什么?该问题与 WinRTXamlToolkit 无关,因为当它BitmapImage被设置为 Web 中的图像时,它会正确保存到磁盘中,所以问题在于 PdfPage 的工作方式。

4

1 回答 1

2

跳过 BitmapImage 并将您的 PDF 直接加载到 WriteableBitmap 中:

WriteableBitmap wb = new WriteableBitmap(1,1);
await wb.SetSourceAsync(str);

无法从 BitmapImage 中提取像素,因此 WriteableBitmapFromBitmapImageExtension.FromBitmapImage 必须从其他地方获取数据:当从 Web 加载 BitmapImage 时它可以工作,因为 FromBitmapImage 可以获取 BitmapImage 的 UriSource 并将该 URI 加载到 WriteableBitmap 中。

于 2015-02-27T07:01:16.900 回答