How to Convert ImageSource to byte[]?

人走茶凉 提交于 2020-01-15 12:13:10

问题


I try to find in google how to convert imageSource to byte[] - and i can't find the why to do it.

Someone can help here ?

Thanks.


回答1:


If you have a BitmapSource you can use BitmapSource.CopyPixels Method (Array, Int32, Int32)

Or alternativeley, for example if you need a ARGB byte sequence:

var bmp = new WriteableBitmap((BitmapSource)source);
byte[] pixels = bmp.Pixels.SelectMany(p => new byte[]
{
    (byte)p,
    (byte)(p >> 8),
    (byte)(p >> 16),
    (byte)(p >> 24)
}).ToArray();


来源:https://stackoverflow.com/questions/5883822/how-to-convert-imagesource-to-byte

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