无法找到ChooserEventArgs类

时间:2011-05-06 19:31:09

标签: c# windows-phone-7 camera

我想打开Windows Phone 7相机,拍一下然后操纵那张照片。但问题是,当我试图覆盖OnChooserReturn函数时,它也会给我错误no suitable method found to override当我想要捕获从相机返回的内容时我会使用它:

ChooserEventArgs<PhotoResult> args = new ChooserEventArgs<PhotoResult>()

虽然我正在使用这两个指令

,但它给出了错误The type or namespace name 'ChooserEventArgs' could not be found (are you missing a using directive or an assembly reference?)
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

问题是什么?如何解决这些问题?

1 个答案:

答案 0 :(得分:3)

听起来您正在尝试使用旧SDK或至少基于过时SDK的指南。要让手机启动相机,然后引用捕获的图像,请使用CameraCaptureTask。您将需要以下使用语句:

using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;

代码中的某处(可能是按钮点击事件),你这样做是为了启动相机:

CameraCaptureTask cct = new CameraCaptureTask();
cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
cct.Show();

然后你像这样处理完成的事件(假设你有一个名为image的Image控件):

void cct_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        BitmapImage bimg = new BitmapImage();
        bimg.SetSource(e.ChosenPhoto);
        this.image.Source = bimg;
    }            
}

此处的文档:http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.cameracapturetask(v=VS.92).aspx