Saving File to Byte Array in Windows 8 WinRT
I’ve been hitting my head to the ground for a couple of days trying send a byte array that represents my Image to my WCF Service in Windows 8, things has changed a lot when it comes to IO and Streams in Windows 8 so I included my code here for others to use
Covert File to Byte Array
- private async Task<byte[]> ConvertImagetoByte(StorageFileimage)
- {
- IRandomAccessStream fileStream = await image.OpenAsync(FileAccessMode.Read);
- var reader = new Windows.Storage.Streams.DataReader(fileStream.GetInputStreamAt(0));
- await reader.LoadAsync((uint)fileStream.Size);
- byte[] pixels = new byte[fileStream.Size];
- reader.ReadBytes(pixels);
- return pixels;
- }