-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Labels
⚒ EnhancementNew feature or requestNew feature or request
Description
Description
Add memory buffer APIs that can return an array or a stream
New APIs
IImage
byte[] ToArray(int quality = 90)
Stream AsStream(int quality = 90)
ReadOnlySpan<byte> AsReadOnlySpan(int quality = 90)Usage - ToArray()
byte[] buffer;
using (var image = new HeifImage("MyImage.heic"))
using (var primary = image.PrimaryImage())
{
buffer = primary.ToArray();
}
// do something with bufferUsage - AsStream
Stream stream;
using (var image = new Heifimage("MyImage.heic"))
using (var primary = image.PrimaryImage())
{
stream = primary.AsStream();
}
// do something with stream
// don't forget to dispose of your stream
stream?.Dispose();Usage - AsReadOnlySpan
This one is a little tricky as Span<T> gives us access to native memory. If we allow C# to operate on native memory we should ensure it happens within the IDisposable using block otherwise there will be a memory leak.
ReadOnlySpan<byte> span;
using (var image = new HeifImage("MyImage.heic"))
using (var primary = image.PrimaryImage())
{
ReadOnlySpan<byte> span = primary.AsReadOnlySpan();
// do something with span
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
⚒ EnhancementNew feature or requestNew feature or request