ある WriteableBitmap のピクセル バッファを別の WriteableBitmap にコピーしようとしているという問題が発生しており、本質的に WriteableBitmap オブジェクトのコピーが提供されています。ただし、これを実行しようとすると、2 番目の WriteableBitmap のストリーム長が短すぎて最初の WriteableBitmap のすべての値を保持できないという問題が発生します。以下にコードを投稿しました。ウェブカメラから元のデータをキャプチャしていることに注意してください。ただし、「ps」オブジェクトのストリーム サイズを wb1 および wb2 と比較すると、ps のサイズはそれらの両方よりもはるかに小さいです。私が混乱しているのは、wb2 ストリーム サイズが wb1 より小さい理由です。助けてくれてありがとう。
private MemoryStream originalStream = new MemoryStream();
WriteableBitmap wb1 = new WriteableBitmap((int)photoBox.Width, (int)photoBox.Height);
WriteableBitmap wb2 = new WriteableBitmap((int)photoBox.Width, (int)photoBox.Height);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
var ps = new InMemoryRandomAccessStream();
await mc.CapturePhotoToStreamAsync(imageProperties, ps);
await ps.FlushAsync();
ps.Seek(0);
wb1.SetSource(ps);
(wb1.PixelBuffer.AsStream()).CopyTo(originalStream); // this works
originalStream.Position = 0;
originalStream.CopyTo(wb2.PixelBuffer.AsStream()); // this line gives me the error: "Unable to expand length of this stream beyond its capacity"
Image img = new Image();
img.Source = wb2; // my hope is to treat this as it's own entity and modify this image independently of wb1 or originalStream
photoBox.Source =wb1;