Skip to content

Is there a "RawEncoder", or any way to save the raw pixel bytes instead of using an image format such as PNG or JPG? #1308

Answered by amoerie
amoerie asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the quick reply!

I must apologize, I did find some documentation after all that was helpful, this page contained some helpful pointers that I missed during my initial search: https://docs.sixlabors.com/articles/imagesharp/pixelbuffers.html

I came up with something very similar to your suggestion @JimBobSquarePants :

P.S. I think your suggestion still requires to convert the Span of TPixel to Span of byte using MemoryMarshal before being able to write to a stream, unless I am mistaken.

    public class RawEncoder: IImageEncoder
    {
        public void Encode<TPixel>(Image<TPixel> image, Stream stream) where TPixel : unmanaged, IPixel<TPixel>
        {
            if(image.TryG…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

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

@amoerie
Comment options

Answer selected by amoerie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants