winPhone开启摄像头
来源:互联网 发布:洲际弹道导弹 知乎 编辑:程序博客网 时间:2024/05/01 15:17
前台代码:
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="#eee">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="ContentPanel" Margin="12,0,12,578" Grid.Row="1">
<ListBox Height="768" Margin="-12,0,-12,-578" Name="listBox1" Opacity="8" VerticalAlignment="Center">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Width="500" Height="500" Margin="0,5,0,5"
Source="{Binding}"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
<!--演示 ApplicationBar 用法的示例代码-->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="appbar.feature.camera.rest.png" Text="按钮 1" Click="ApplicationBarIconButton_Click" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
后台代码:
private ObservableCollection<BitmapImage> bitmapImages = new ObservableCollection<BitmapImage>();
public Page4(){
InitializeComponent();
LoadImg();
listBox1.ItemsSource = bitmapImages;
}
private void LoadImg()
{
bitmapImages.Clear();
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
try
{
foreach (string file in isf.GetFileNames("baby"+"*.jpg"))//遍历所有jpg图片
{
BitmapImage bmpImg = new BitmapImage();
using (Stream stream = isf.OpenFile(file, FileMode.Open))
{
bmpImg.SetSource(stream);
}
bitmapImages.Add(bmpImg);
}
}
catch { }
}
void pcTask_Completed(object sender, PhotoResult e)
{
if (e.Error != null)
{
CommonHelper.MsgBox("执行失败!");
return;
}
if (e.TaskResult == TaskResult.OK)
{
//BitmapImage img = new BitmapImage();
//img.SetSource(e.ChosenPhoto);//用图片流初始化BitmapImage图片对象
string name = (string)IsolatedStorageSettings.ApplicationSettings["name"];
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
string filename = "baby"+name+DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
using (e.ChosenPhoto)
{
Stream stream = isf.CreateFile(filename);
e.ChosenPhoto.CopyTo(stream);
BitmapImage bmpImg = new BitmapImage();
bmpImg.SetSource(stream);
bitmapImages.Add(bmpImg);
}
}
}
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
PhotoChooserTask pcTask = new PhotoChooserTask();
pcTask.ShowCamera = true;//显示拍照按钮,用户即可以选择图片,又可以拍照
pcTask.PixelHeight = 100;//如果设定了PixelHeight和PixelWidth,则选择后的图片要求用户截取成合适的大小!
pcTask.PixelWidth = 100;//可以用来实现上传QQ头像的功能。
pcTask.Completed += new EventHandler<PhotoResult>(pcTask_Completed);
pcTask.Show();
}
}
- winPhone开启摄像头
- winphone
- 开启X230摄像头
- DirectShow 开启摄像头
- JMF开启摄像头
- 开启自定义摄像头
- NOKIA 6260 无法开启摄像头
- ubuntu 开启摄像头和samba
- 在ubuntu下开启摄像头
- orangepi开启yuv摄像头驱动
- winphone 新闻
- winphone记录
- winphone笔记
- 一段开启摄像头的代码(BCB)
- 发一段开启摄像头的代码
- 发一段开启摄像头的代码
- 电脑摄像头开启之后图形倒立
- OpenCV学习笔记(2)-----开启摄像头
- 黑马程序员之TCP
- JAVA NIO 简介
- 关于颜色直方图和反向投影的一些理解
- 几何题-求圆柱最大体积
- onunload调用下面js函数
- winPhone开启摄像头
- 黑马程序员——正则表达式
- 全球50个最有特色网站
- MySQL Internals——IN,OR,BETWEEN哪个更快?
- 破解 inode 校园网多网卡限制方法
- DOM在表格中的应用
- 黑马程序员——JDK1.5新特性
- 第12堂课后作业
- 朴素的模式匹配算法