在开发windows phone 7 的过程中,如果想要使用相机拍照或者选择相片该如何调用呢?
可以先using Microsoft.Phone.Tasks;
一、选择相片:
1.定义相片选择函数:
void pc_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
this.image1.Source = bitmap;
}
else
{
image1.Source = null;
}
}
2.然后在button添加选择相片事件:
pc.PixelHeight = 156;
pc.PixelWidth = 265;
pc.Show();
二、拍照:
1.定义照相函数:
void cct_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
this.image1.Source = bitmap;
}
else
{
image1.Source = null;
}
}
2.添加拍照button事件:
CameraCaptureTask cct = new CameraCaptureTask();
cct.Completed += cct_Completed;
cct.Show();