您的位置:首页 > 其它

CameraCaptureTask的用法

2010-08-31 11:41 316 查看
首先要引用相关的名字空间:using Microsoft.Phone.Tasks;

然后在Page里定义一个变量:CameraCaptureTask cameraCaptureTask;
然后要在Page的Constructor里添加实例化和关联Completed事件处理方法:

cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);

如下代码所示:

代码

void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);

//save the captured photo to settings
(Application.Current as App).photoTaked = new BitmapImage();
(Application.Current as App).photoTaked = bmp;
//MessageBox.Show(e.OriginalFileName);
}
else
{
(Application.Current as App).photoTaked = null;
}
}

然后是在调用摄像头的地方加入show()方法:

void retake_Click(object sender, EventArgs e)
{
cameraCaptureTask.Show();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: