照片捕获流到软件位图
本文关键字:软件 位图 照片 | 更新日期: 2023-09-27 18:32:16
My Code:
var stream = new InMemoryRandomAccessStream();
ImageEncodingProperties properties = ImageEncodingProperties.CreateJpeg();
await _mediaCapture.CapturePhotoToStreamAsync(properties, stream);
IBuffer buffer = new byte[stream.Size].AsBuffer();
await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None);
SoftwareBitmap sfbmp = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, 4176, 3120); // Exception is thrown here
例外:
用于响应的内存不足
老实说,我对位图缓冲区一无所知,所以有人可以帮助我吗?
我使用BitmapDecoder解决了它
var stream = new InMemoryRandomAccessStream();
ImageEncodingProperties properties = ImageEncodingProperties.CreateJpeg();
await _mediaCapture.CapturePhotoToStreamAsync(properties, stream);
var decoder = await BitmapDecoder.CreateAsync(stream);
SoftwareBitmap sfbmp = await decoder.GetSoftwareBitmapAsync();