1

I have a WPF pdf viewer code. I'm trying to convert it into UWP. To render the pages of a pdf, WPF uses System.Windows.Media.Imaging.WriteableBitmap. UWP compatible Windows.UI.Xaml.Media.Imaging.WriteableBitmap doesn't contain all the functionalities as in wpf compatible package. I can't find functions to replace the below methods.

WriteableBitmap renderTarget;
var bitmapFormat = GetBitmapFormat(renderTarget.Format);
renderTarget.Lock();
renderTarget.AddDirtyRect(new Int32Rect(rectDest.left, rectDest.top, rectDest.width, rectDest.height));
renderTarget.Unlock();

Does anyone know a workaround or new package which I can use to replace those methods( Format, Lock, AddDirtyRect, Unlock)?

The above package also should have a constructor that accepts following parameters.

WriteableBitmap(int pixelWidth, int pixelHeight, double dpiX, double dpiY, PixelFormat pixelFormat, BitmapPalette palette);

Additionally, Need to replace System.Windows.Media.PixelFormats and use a UWP compatible one. UWP compatible Windows.Graphics.Imaging.BitmapPixelFormat does not contain all pixel formats such as Bgra32, Bgr32, Bgr24).

  • See the Remarks section on the [WriteableBitmap.PixelBuffer](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.writeablebitmap.pixelbuffer#Windows_UI_Xaml_Media_Imaging_WriteableBitmap_PixelBuffer) page. – Clemens Feb 07 '20 at 08:51
  • 1
    Hi, If you need to render Pdf in UWP, you may need a new way to adopt `PdfDocument` and display it with `BitmapImage`. Here is the [complete example](https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/PdfDocument) – Richard Zhang Feb 10 '20 at 00:44

0 Answers0