【问题标题】:Cannot add flipview image when reading pdf on windows phone 8.1在 Windows Phone 8.1 上阅读 pdf 时无法添加翻转视图图像
【发布时间】:2015-08-19 19:55:17
【问题描述】:

我在 windows phone 8.1 上做了一个使用 xfinium 阅读 pdf 的应用程序。在阅读 pdf 时添加翻转视图时遇到问题。 图片不显示并显示错误信息如link

代码:

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());
                    }
                }

            }
        }

如何处理?

【问题讨论】:

    标签: c# pdf image-processing windows-phone-8.1 flipview


    【解决方案1】:

    我的建议是检查 imageStream 的长度及其位置。 Position 应为 0,imageStream.Length 应等于 rs.Bitmap.Length。如果它们不同,请将示例项目发送到 XFINIUM.PDF 支持。
    免责声明:我在开发 XFINIUM.PDF 库的公司工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多