有没有办法将BitmapImage(Windows.UI.Xaml.Media.BitmapImage)转换为Byte []数组?我试过的一切都没用...
另一个可能的情况(如果BitmapImage无法转换为字节数组)是从Web下载图像,然后将其转换为数组...
但我不知道该如何做...
如果有人有想法,那就太好了。
当前尝试:
HttpClient http = new HttpClient();
Stream resp = await http.GetStreamAsync("http://localhost/img/test.jpg");
var ras = new InMemoryRandomAccessStream();
await resp.CopyToAsync(ras.AsStreamForWrite());
BitmapImage bi = new BitmapImage();
bi.SetSource(ras);
byte[] pixeBuffer = null;
using (MemoryStream ms = new MemoryStream())
{
int i = bi.PixelHeight;
int i2 = bi.PixelWidth;
WriteableBitmap wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
Stream s1 = wb.PixelBuffer.AsStream();
s1.CopyTo(ms);
pixeBuffer = ms.ToArray();
}
但是它不起作用...... i和i2总是被设置为0。因此,ras不能正常工作......发生了什么?谢谢