2017-05-16 14 views
1

にSystem.IO.Streamからの変換:C#UWPが、私は例外を取得ので、私は、IRandomAccessStreamWithContentTypeが、カントを取得しようとしていますWindows.Storage.Streams.IRandomAccessStreamWithContentType

"This IRandomAccessStream does not support the CloneStream method because it requires cloning and this stream does not support cloning." 

をそして、これが最後の行に起こります次のコード:

PixelDataProvider pix = await decoder.GetPixelDataAsync(
       BitmapPixelFormat.Bgra8, 
       BitmapAlphaMode.Straight, 
       transform, 
       ExifOrientationMode.IgnoreExifOrientation, 
       ColorManagementMode.ColorManageToSRgb); 
byte[] pixels = pix.DetachPixelData(); 

Stream pixStream = cropBmp.PixelBuffer.AsStream(); 
pixStream.Write(pixels, 0, (int)(width * height * 4)); 
IRandomAccessStream iStream= pixStream.AsRandomAccessStream(); //dafaq with streams 
RandomAccessStreamReference iReferenceStream= RandomAccessStreamReference.CreateFromStream(iStream); 
IRandomAccessStreamWithContentType newStream = await iReferenceStream.OpenReadAsync(); 

回避策などはありますか?

私もこの方法を試してみました1

編集、まだ動作しません。 (しかし、今、私はクローンが失敗したことをnullではない取得)あなたのコードから

答えて

0

を、あなたがBitmapDecoderを使用しているようです。 BitmapDecoderは、ビットマップコンテナデータおよび最初のフレームからのデータへの読み取りアクセスを提供します。

BitmapEncoder.CreateForTranscodingAsyncに書き込むエンコーダ用に新しいInMemoryRandomAccessStreamを作成し、メモリ内ストリームとデコーダオブジェクトを渡すことができるようにします。例えば

Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/sunset.jpg")).OpenReadAsync(); 
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random); 
Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync(); 
byte[] buffer = pixelData.DetachPixelData(); 
InMemoryRandomAccessStream inMemoryRandomAccessStream = new InMemoryRandomAccessStream(); 
BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryRandomAccessStream, decoder); 
encoder.BitmapTransform.ScaledWidth = 320; 
encoder.BitmapTransform.ScaledHeight = 240; 
await encoder.FlushAsync(); 
inMemoryRandomAccessStream.Seek(0); 
random.Seek(0); 
BitmapImage bitmapImage = new BitmapImage(); 
RandomAccessStreamReference iReferenceStream = RandomAccessStreamReference.CreateFromStream(inMemoryRandomAccessStream); 
IRandomAccessStreamWithContentType newStream = await iReferenceStream.OpenReadAsync(); 
bitmapImage.SetSource(newStream); 
MyImage.Source = bitmapImage; 
関連する問題