您的位置:首页 > 其它

wp如何拍照并获取照片

2012-09-03 12:48 183 查看
wp如何拍照并获取照片

本代码出处:http://yuncode.net/code/c_503c9a5a0870b74

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
//引用
using System.Windows.Media.Imaging;
using Microsoft.Phone.Tasks;

namespace CameraShoot
{
public partial class MainPage : PhoneApplicationPage
{
//相机捕获任务实例
CameraCaptureTask cameraCT = new CameraCaptureTask();
// 构造函数
public MainPage()
{
InitializeComponent();
//手机拍照功能完成后调用
cameraCT.Completed += new EventHandler<PhotoResult>(cameraCT_Completed);
}
//重写触摸屏事件
protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
{
if (e.OriginalSource==txtName)
{
//调用相机
cameraCT.Show();
}
//触摸事件完成
e.Complete();
//不在向父元素传递
e.Handled = true;
base.OnManipulationStarted(e);
}
//完成
void cameraCT_Completed(object sender, PhotoResult e)
{
if (e.TaskResult==TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
//获取包含文件流的和Source不同
bmp.SetSource(e.ChosenPhoto);
//设置图片源
img.Source = bmp;
txtName.Text = e.OriginalFileName;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: