Convert Image<Rgba32> to Byte[] using ImageSharp

天大地大妈咪最大 提交于 2019-12-10 17:45:54

问题


How can I convert an image to array of bytes using ImageSharp library?

Can ImageSharp library also suggest/provide RotateMode and FlipMode based on EXIF Orientation?


回答1:


If you are looking to convert the raw pixels into a byte[] you do the following.

var bytes = image.SavePixelData()

If you are looking to convert the encoded stream as a byte[] (which I suspect is what you are looking for). You do this.

using (var ms = new MemoryStream())
{
    image.Save(ms, imageFormat);
    return ms.ToArray();
}



回答2:


Onto the second question: There's a transformation API function called AutoOrient(). Look it up ;)



来源:https://stackoverflow.com/questions/50025908/convert-imagergba32-to-byte-using-imagesharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!