/// <summary> /// あとでファイルとして保存できるように共有Bitmapの情報を保存しておく. /// </summary> /// <param name="inStream"></param> /// <returns></returns> private async Task KeepSharedBitmapInfoAsync(Windows.Storage.Streams.IRandomAccessStreamWithContentType inStream) { var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inStream); this.fileName = DateTimeOffset.UtcNow.Ticks.ToString() + decoder.DecoderInformation.FileExtensions[0]; this.imageStream = new InMemoryRandomAccessStream(); inStream.Seek(0); await Windows.Storage.Streams.RandomAccessStream.CopyAsync(inStream, imageStream); }
// converts image to byte[] public async static Task <byte[]> ImageToByteArray(StorageFile file) { byte[] fileBytes = null; // convert file to byte[] if (file != null) { using (Windows.Storage.Streams.IRandomAccessStreamWithContentType stream = await file.OpenReadAsync()) { fileBytes = new byte[stream.Size]; using (DataReader reader = new DataReader(stream)) { await reader.LoadAsync((uint)stream.Size); reader.ReadBytes(fileBytes); } } } return(fileBytes); }