我正在使用WriteableBitmapEx库来编辑使用Windows 8 Pro的平板电脑摄像头拍摄的图像。我每次调用GetPixel()函数时都会收到AccessViolationException,这里是代码:
Windows.Media.Capture.MediaCapture captureMgr = new MediaCapture();
await captureMgr.InitializeAsync();
IRandomAccessStream memoryStream = new InMemoryRandomAccessStream();
await captureMgr.CapturePhotoToStreamAsync(imageProperties, memoryStream);
await memoryStream.FlushAsync();
memoryStream.Seek(0);
WriteableBitmap tmpImage = new WriteableBitmap(1, 1);
tmpImage.SetSource(memoryStream);
tmpImage.GetPixel(1, 1); // An AccessViolationException occurs.
我做错了什么?
答案 0 :(得分:4)
尝试使用内置方法来创建WriteableBitmap
。
WriteableBitmap tmpImage = await BitmapFactory.New(1, 1).FromStream(memoryStream);
tmpImage.GetPixel(1, 1);
这应确保您的图像在被访问之前已加载到WriteableBitmap中。