Monday, February 2, 2015

Byte array is empty when fetching using Xamarin Forms 1.3 and XLabs 2.0

I stumbled upon a small "bug/feature" after updating a Xamarin.Forms app to 1.3 and XLabs 2.0. The small snippet of code below is called after a pictures is selected or taken.

Photo is a ImageSource that belongs to the ViewModel for the View. I also needed the raw bytes later on so I simply used the Read method of the stream returned.

After the update the bytes-array was simply set to 0 for each byte in the array until I reset the position before the read. No exception, simply just empty.

    Photo = ImageSource.FromStream(() => mediaFile.Source);
    var bytes = new byte[mediaFile.Source.Length];
    mediaFile.Source.Position = 0;

    mediaFile.Source.Read(bytes, 0, (int)mediaFile.Source.Length);

Have a nice day!

No comments:

Post a Comment