我能够将byte []转换为图像:
byte[] myByteArray = ...; // ByteArray to be converted
MemoryStream ms = new MemoryStream(my);
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
Image img = new Image();
img.Source = bi;
Run Code Online (Sandbox Code Playgroud)
但是我无法将Image转换回byte []!我在互联网上找到了一个适用于WPF的解决方案:
var bmp = img.Source as BitmapImage;
int height = bmp.PixelHeight;
int width = bmp.PixelWidth;
int stride = width * ((bmp.Format.BitsPerPixel + 7) / 8);
byte[] bits = new byte[height * stride];
bmp.CopyPixels(bits, stride, 0);
Run Code Online (Sandbox Code Playgroud)
Silverlight库非常小,以至于BitmapImage类没有名为Format的属性!
有没有人能解决我的问题.
我在互联网上搜索了很长时间才找到解决方案,但是没有解决方案,这在Silverlight中有效!
谢谢!
silverlight ×1