I'm trying to Invert color of a page in my UWP
pdf reader (using
Windows.Data.Pdf) .
Piece of my code:
using Windows.Data.Pdf;
private PdfPageRenderOptions _ro;
private PdfPage _page;
private WriteableBitmap wb;
...
private async void InvertPage() {
using(var stream = new InMemoryRandomAccessStream()) {
await _page.RenderToStreamAsync(stream,_ro);
await wb.SetSourceAsync(stream);
// also tried wb.SetSource(stream);
wb.Invert(); // ERROR IN HERE
}
}
I have not problem in Getting images as normal (No Inverting) or inverting Pixels byte by byte but it's toooo slow so I'm trying to Invert using Invert()
in Windows.UI.Xaml.Media.Imaging.WriteableBitmap
but it throws an exception!
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
HINT:
When I use await _page.RenderToStreamAsync(stream);
instead , everything works fine. (but It's necessary to include PdfPageRenderOptions in stream
)