###前提・実現したいこと
こんにちは。いつもたいへんお世話になります。
本日はVisual Studio 2017 CommunityでUWP(Windows 10 Phone)のカメラを作っています。困っていることがあります。
InMemoryRandomAccesssStream()をbyte[]にしようとしています。
エラーが出ていて、お知恵拝借したいです。
###発生している問題・エラーメッセージ
System.Runtime.InteropServices.COMException HResult = 0x8000000B Message=The operation attempted to access data outside the valid range The operation attempted to access data outside the valid range Source=Windows スタック トレース: at Windows.Storage.Streams.DataReader.ReadBytes(Byte[] value)
C#
1var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures); 2StorageFile file = await myPictures.SaveFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName); 3 4using (var captureStream = new InMemoryRandomAccessStream()) 5{ 6 await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream); 7 8 using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) 9 { 10 var decoder = await BitmapDecoder.CreateAsync(captureStream); 11 var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder); 12 13 var properties = new BitmapPropertySet { 14 { "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) } 15 }; 16 await encoder.BitmapProperties.SetPropertiesAsync(properties); 17 18 await encoder.FlushAsync(); 19 20 byte[] fileBytes = new byte[fileStream.Size]; 21 using (DataReader reader = new DataReader(fileStream)) 22 { 23 await reader.LoadAsync((uint)fileStream.Size); 24 reader.ReadBytes(fileBytes); 25 } 26 } 27}
###補足情報(言語/FW/ツール等のバージョンなど)
Windows10 Home 1709 64bit
Microsoft Visual Studio Community 2017
Version 15.1 (26403.3) Release
VisualStudio.15.Release/15.1.0+26403.3
Microsoft .NET Framework
Version 4.7.02556
インストールされているバージョン:Community
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。