Skip to content

How to convert image to rgba8888 byte array? #1941

Answered by antonfirsov
BenMcLean asked this question in Ideas
Discussion options

You must be logged in to vote

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 the Span<Rgba32> to Span<byte>, and eventually copy it to a byte[] 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.

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.

Replies: 2 comments 11 replies

Comment options

You must be logged in to vote
9 replies
@BenMcLean
Comment options

@BenMcLean
Comment options

@antonfirsov
Comment options

@ghost
Comment options

@ghost
Comment options

Answer selected by JimBobSquarePants
Comment options

You must be logged in to vote
2 replies
@BenMcLean
Comment options

@JimBobSquarePants
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants