有沒有辦法將BitmapImage(Windows.UI.Xaml.Media.BitmapImage)轉換爲Byte []數組?沒有我已經嘗試工作.... 另一種可能的情況下(如果BitmapImage不能轉換爲字節數組)是從網站下載圖像,然後將其轉換爲數組...Metro應用程序 - 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();
}
但它不工作...我& I2總是設置爲0,所以ras基因不能正常工作....這是怎麼回事?
感謝