-
In 1.0.0-beta0007 I could get an array of an image with: Image<Rgba32> img = SixLabors.ImageSharp.Image.Load<Rgba32>(ImagePath);
Rgba32[] Colors = img.GetPixelSpan().ToArray(); Nice! But then, trying to upgrade to 2.1.2, I see this method been reworked once to Digging a bit about in Stackoverflow I found this answer: https://stackoverflow.com/questions/50025908/convert-imagergba32-to-byte-using-imagesharp#answer-63758770 That was the closest I found to what should be the right way to go... But then, there's quite a fight in this answer's comments section. I felt it was the right thing to post this here to see if there's a best practice now to do the same in the current, 2.1.2, version of the library. Any idea? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
For now it seems re-implementing it works via this extension method in my project: public static Span<T> GetPixelSpan<T>(this Image<T> imageRef) where T : unmanaged, IPixel<T>
{
var memoryFootprint = new T[imageRef.Width * imageRef.Height];
var pixelSpan = new Span<T>(memoryFootprint);
imageRef.CopyPixelDataTo(pixelSpan);
return pixelSpan;
} Looking forward to everyone's insight on this matter. And if that's adequate an approach, I hope this helps everyone else facing this issue. |
Beta Was this translation helpful? Give feedback.
For now it seems re-implementing it works via this extension method in my project:
Looking forward to everyone's insight on this matter. And if that's adequate an approach, I hope this helps everyone else facing this issue.