[英]Cannot add flipview image when reading pdf on windows phone 8.1
I made an application on windows phone 8.1 for reading pdf using xfinium. 我在Windows Phone 8.1上创建了一个使用xfinium读取pdf的应用程序。 I have problems when adding flipview upon reading the pdf.
在阅读pdf时添加flipview时遇到问题。 Image is not displayed and display an error message such as this link
未显示图像,并显示错误消息,例如此链接
Code: 码:
async private void LoadFile(string name)
{
StorageFolder installedLocation = ApplicationData.Current.LocalFolder;
StorageFolder koleksibuku = await installedLocation.CreateFolderAsync("koleksibuku", CreationCollisionOption.OpenIfExists);
IReadOnlyList<StorageFile> files = await koleksibuku.GetFilesAsync();
StorageFolder thumbfolder = await installedLocation.CreateFolderAsync("thumb", CreationCollisionOption.OpenIfExists);
foreach (StorageFile file in files)
{
if (file.DisplayName == name)
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
Stream fileStream = stream.AsStreamForRead();
PdfFixedDocument document = new PdfFixedDocument(fileStream);
//fileStream.Dispose();
(Application.Current as App).Document = document;
int i = 0;
for (i = 0; i < document.Pages.Count; i++)
{
int index = i;
var t = Task<PdfBgraByteRenderingSurface>.Factory.StartNew(() =>
{
PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[index]);
PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface<PdfBgraByteRenderingSurface>(96, 96);
PdfRendererSettings settings = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
renderer.ConvertPageToImage(settings);
return rs;
})
.ContinueWith(value =>
{
PdfBgraByteRenderingSurface rs = value.Result;
WriteableBitmap pageBitmap = new WriteableBitmap(rs.Width, rs.Height);
Stream imageStream = pageBitmap.PixelBuffer.AsStream();
imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);
flipView.SelectionChanged += flipView_SelectionChanged;
flipView.Loaded += flipView_Loaded;
flipView.ItemsSource = pageBitmap;
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}
}
}
How to handle it? 如何处理?
My recommendation is to check the Length of the imageStream and its Position. 我的建议是检查imageStream的长度及其位置。 The Position should be 0 and the imageStream.Length should be equal to rs.Bitmap.Length.
Position应该为0,并且imageStream.Length应该等于rs.Bitmap.Length。 If they are different please send a sample project to XFINIUM.PDF support.
如果它们不同,请将示例项目发送给XFINIUM.PDF支持。
Disclaimer: I work for the company that develops XFINIUM.PDF library. 免责声明:我为开发XFINIUM.PDF库的公司工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.