Is there a way to convert BitmapImage (Windows.UI.Xaml.Media.BitmapImage) to a Byte [] array? Nothing I tried working ... Another possible scenario (if BitmapImage cannot be converted to an array of bytes) is to download an image from the Internet and then convert it to an array ...
But I do not know how I can do this ... It would be very nice if anyone has an idea.
Current attempt:
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();
}
But this does not work ... i and i2 are always equal to 0. Therefore, ras does not work correctly ... What is happening?
thank
source
share