我遇到了一个问题,我试图将一个 WriteableBitmap 的像素缓冲区复制到另一个 WriteableBitmap,本质上是提供 WriteableBitmap 对象的副本。但是,当我尝试这样做时,我遇到了第二个 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;