我能一个byte []转换为图像:的Silverlight:图像为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;
但我不能够将图像转换回一个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);
Silverlight的libary是如此的渺小,类的BitmapImage没有财产称为格式!
有没有人解决我的问题的想法。
我在网上搜索了很长时间才找到解决方案,但没有解决方案,它在silverlight中工作!
谢谢!
你有这方面的工作?特别是bitmapSource.SetSource(流);部分?为我引发一个例外。 – jayarjo 2012-10-25 11:41:22