我正在爲Windows 8.1的Windows應用商店應用程序工作,但找不到任何解決我需要的操作。我正在嘗試將PDF頁面的圖像保存到本地應用程序數據存儲中。我有以下:將PDF保存爲文件
private async void GetFirstPage()
{
// Retrieve file from FutureAccessList
StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(token);
// Truncate last 4 chars; ex: '.pdf'
FileName = file.Name.Substring(0, file.Name.Length - 4);
// Get access to pdf functionality from file
PdfDocument doc = await PdfDocument.LoadFromFileAsync(file);
// Get a copy of the first page
PdfPage page = doc.GetPage(0);
// Below could be used to tweak render options for optimizations later
//PdfPageRenderOptions options = new PdfPageRenderOptions();
// Render the first page to the BitmapImage
InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
await page.RenderToStreamAsync(stream);
// Common code
Cover.SetSource(stream);
// Convert the active BitmapImage Cover to a storage file to be stored locally
// ???
}
可變,蓋,是在XAML綁定到顯示圖像給用戶的的BitmapImage。我想將此圖像保存到我的本地應用程序數據中,以便每次打開應用程序時都不必通過PDF庫重新渲染它!問題是我不能從流中保存任何Windows應用程序應用程序,除非它是我所知的文本(對我來說沒有文件流或文件輸出流),並且Cover的URI源是空的,因爲它來自流,使得很難將我的BitmapImage,Cover,保存到StorageFile中,以便正確保存Windows Store。
目前一切都適用於我,每當我的應用程序打開時,我都感到沮喪,從頭開始重新將pdf頁面呈現給我的bitmapimage。預先感謝您的任何意見!
這就像一個魅力,它現在真的有道理!我一定是密集的。<非常感謝你:) – Proto 2014-11-02 19:16:00