-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept and return ReadOnlySpan<byte> instead of IntPtr #16
Comments
Hi! I'm glad you're finding the library useful! This sounds like a good idea, I can start working on it when I get back to my computers (likely next week). I will update this issue when it's done. |
Hi! Version 1.5.0 now has overloads of the render methods (both for the However, you should note that:
All in all, if you just need to manipulate the image using ImageSharp, it is probably better if you just use the MuPDFCore overload that returns a The int bufferSize = ...
byte[] buffer = new byte[bufferSize];
GCHandle bufferHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
IntPtr bufferPointer = bufferHandle.AddrOfPinnedObject();
// Do stuff with bufferPointer.
bufferHandle.Free(); As long as you don't wait too much before freeing the In any case, if you need better performance, you may need to look into some other graphics library that lets you work directly with pixel data stored in unmanaged memory (perhaps something like SkiaSharp?)... |
This is great! Thanks for the detailed explanation. I will give it a spin right away! |
Hello, first of all let me say that this is a great library and especially the multithreaded render.
Is there somewhere on the roadmap the ability to expose an API with
Span<byte>
instead ofIntPtr
?The reason is that in most of the cases, after rendering an e.g. PDF file, we have to either change the exported file format or perform some sort of image manipulation (with another library e.g. ImageSharp). Therefore, it would be beneficial to avoid marshalling memory back, holding twice the amount.
The only way I know to expose a
Span<byte>
out of anIntPtr
is by going intounsafe
mode and castingIntPtr
to avoid*
pointer but this would make my project require an/unsafe
build, which I was really hoping to avoid.Do you have any ideas?
Thanks,
--Theodore
The text was updated successfully, but these errors were encountered: