How to convert image to rgba8888 byte array? #1941
-
I don't know where support questions go so I'm posting here ... let me know if there is a better place. I've got SixLabors.ImageSharp 1.0.4 from NuGet. In my program, the user submits a I want to get the height, width and a byte array in the format of rgba8888, where every four bytes represents one pixel and only pixels are in the array (no header data, no footer data, no metadata, just pixels) so that if you divide the array size by 4 * height then you'd get width and if you divide the array size by 4 * width then you'd get height. There are lots of answers on the Internet for how to do this, but they are all for old versions of ImageSharp and do not work on the current version. Even the documentation does not actually say directly how to do this. It has something about doing things one way with a normal image and another way with a multi-megapixel image and has you converting to a data type called I want a byte array because I want to write code that is agnostic to what image library is being used and will only include ImageSharp in my test project. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
I'm assuming that rgba8888 is equivalent of our If your image is not insanely huge (above 130 Megapixels ~ 11000 x 11000 pixels), the Note that these API-s are about to go in ImageSharp 2.0, because of the necessary changes of the underlying buffer management. There will be
We are intentionally lacking an |
Beta Was this translation helpful? Give feedback.
-
Hey @BenMcLean do you have a Six Labors license? Because this all reads a lot like you’re asking for support. |
Beta Was this translation helpful? Give feedback.
I'm assuming that rgba8888 is equivalent of our
Rgba32
pixel type in my answer.If your image is not insanely huge (above 130 Megapixels ~ 11000 x 11000 pixels), the
TryGetSinglePixelSpan
method should succeed and you should be able to cast theSpan<Rgba32>
toSpan<byte>
, and eventually copy it to abyte[]
just like the docs suggest.Note that these API-s are about to go in ImageSharp 2.0, because of the necessary changes of the underlying buffer management. There will be
image.CopyPixelDataTo
methods instead. See #1739 for more details.