使用WriteableBitmapEx访问像素颜色时出现AccessViolationException [英] AccessViolationException when accessing pixel color using WriteableBitmapEx

查看:150
本文介绍了使用WriteableBitmapEx访问像素颜色时出现AccessViolationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WriteableBitmapEx 库来编辑使用Windows 8 Pro平板电脑的凸轮拍摄的图像.每次我调用GetPixel()函数时都会得到一个AccessViolationException,这是代码:

I'm using WriteableBitmapEx library to edit an image taken with tablet's cam with Windows 8 Pro. I'm getting an AccessViolationException every time I call to GetPixel() function, here's the code:

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.

我做错了什么?

推荐答案

尝试使用内置方法来创建您的WriteableBitmap.

Try using the built in methods to create your WriteableBitmap instead.

WriteableBitmap tmpImage = await BitmapFactory.New(1, 1).FromStream(memoryStream);  
tmpImage.GetPixel(1, 1);

这应该确保您的图像在访问之前已加载到WriteableBitmap中.

This should ensure that your image has been loaded into the WriteableBitmap before being accessed.

这篇关于使用WriteableBitmapEx访问像素颜色时出现AccessViolationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆