I think it is possible through base64, but is it possible by more simple way?
Thanks!
DEBUG and RELEASE modeWhat do you want in the byte array?
I want to compress image to webp by this https://github.com/JosePineiro/WebP-wrapper
after ImageSharp Resizing.
I wouldn't bother with WebP it's a dead end. You'd be much better off using MozJpeg.
Quickest way would probably be the following though.
image.Pixels.NonPortableCast<Rgb32, byte>().ToArray()
Why not add a method to get bytes array directly, calling NonPortableCast requires referencing System.Memory which a little headache add references in many project just to convert image to bytes.
I used this workaround for to convert Image<> to byte[]
MemoryStream memoryStream = new MemoryStream();
image.SaveAsPng(memoryStream);
@fahadabdulaziz Because that's an entirely different thing?!
You're saving the compressed image in png format to a stream. My sample is converting the raw pixels from Span<Rgba32> to byte[].
My method is wrong because it will convert all images to PNG.
Using NonPortableCast requires referencing System.Memory in every project we use this method.
Adding method in the middle like GetBytes() will nor require System.Memory and will keep the format as is.
@fahadabdulaziz
Can you please not spam our issue tracker. If you want a GetBytes() method please follow the instructions in the Contribution Guidelines and start a conversation on Gitter. We can then move on to raising an issue and subsequent PR from there.
Thanks
@JimBobSquarePants I didn't spam your tracker I'm not the issue creator ?!
@fahadabdulaziz You interrupted an open issue with incorrect information and then requested a feature. It's considered poor etiquette to do so.
And yes, the original issue should have been raised as a question on Gitter (@ChristopherRobinSuperStar please take note of that in future)
I'm not trying to come across as harsh, it's just I (and the rest of the team) get several alerts on many devices every time a comment is made here.
If our processes are followed we can keep on top of our workload and deliver the library to the public, If they are not then we waste time sifting through content to identify real issues and our library is delayed.
Oh, thank you! But why WebP it's a dead end?
@ChristopherRobinSuperStar There's multiple issue with the format. They're described by a chap on Hacker News who is known as an authority on image compression.
Most helpful comment
Why not add a method to get bytes array directly, calling NonPortableCast requires referencing System.Memory which a little headache add references in many project just to convert image to bytes.
I used this workaround for to convert Image<> to byte[]