[windows phone]代码库
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;
}
}
}
}
初级程序员
by: 云代码会员 发表于:2019-10-21 14:41:12 顶(0) | 踩(0) 回复
0000
回复评论