wp7在程序中直接开启摄像头(非选择器)
来源:互联网 发布:天书世界武将转生数据 编辑:程序博客网 时间:2024/05/16 06:52
很久没有做wp7开发了,最近看到微信在程序中打开摄像头进行二维码,扫描忽然性起,遍做了下研究,然后发现原来是用到了using Microsoft.Devices;命名空间下的
PhotoCamera 对象,把它赋值给VideoBrush 就可以了
但是真机测试发现图像和真实图像是颠倒90度的,后来才发现,原来PhotoCamera 会将图像旋转一个角度,我们只要获取到这个角度做下处理就可以了
double d= photocamera.Orientation;在这里获取到图像顺时针旋转的角度
video.RelativeTransform = 在这个把他给前台的VideoBrush 就可以了
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = d };
做了个小demo,在此分享给大家
下面的是前台xaml页面代码
<phone:PhoneApplicationPage
x:Class="MyPocketBook.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel 包含应用程序的名称和页标题-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="页面名称" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="516"></RowDefinition>
<RowDefinition Height="91*"></RowDefinition>
</Grid.RowDefinitions>
<Grid x:Name="butlist" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Name="btnstart" Content="开启闪光灯" Grid.Column="0" Width="200" Click="btnok_Click"></Button>
<Button Name="btnstop" Content="关闭闪光灯" Grid.Column="1" Width="200" Click="btnstop_Click"></Button>
</Grid>
<Rectangle Grid.Row="0">
<Rectangle.Fill>
<VideoBrush x:Name="video"></VideoBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
<!--演示 ApplicationBar 用法的示例代码-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="按钮 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="按钮 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="菜单项 1"/>
<shell:ApplicationBarMenuItem Text="菜单项 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->
</phone:PhoneApplicationPage>
这里是后台代码,都加了注释的
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 Microsoft.Devices;
namespace MyPocketBook
{
public partial class MainPage : PhoneApplicationPage
{
PhotoCamera photocamera = new PhotoCamera();
// 构造函数
public MainPage()
{
InitializeComponent();
//相机初始化事件
photocamera.Initialized += new EventHandler<CameraOperationCompletedEventArgs>(photocamera_Initialized);
//拍摄序列完成时发生
photocamera.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(photocamera_CaptureCompleted);
//当有缩略图像可用时发生
photocamera.CaptureThumbnailAvailable += new EventHandler<ContentReadyEventArgs>(photocamera_CaptureThumbnailAvailable);
double d= photocamera.Orientation;
video.RelativeTransform =
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = d };
video.SetSource(photocamera);
}
void photocamera_CaptureThumbnailAvailable(object sender, ContentReadyEventArgs e)
{
throw new NotImplementedException();
}
void photocamera_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e)
{
throw new NotImplementedException();
}
void photocamera_Initialized(object sender, CameraOperationCompletedEventArgs e)
{
}
bool i = true;
private void btnok_Click(object sender, RoutedEventArgs e)
{
photocamera.FlashMode = FlashMode.On;
photocamera.Focus();
}
private void btnstop_Click(object sender, RoutedEventArgs e)
{
i = false;
photocamera.FlashMode = FlashMode.Off;
}
}
}
个人博客:http://blog.amtemai.com
- wp7在程序中直接开启摄像头(非选择器)
- 在非控制台程序中开启控制台进行信息的输出
- 【iphone】在程序中调用摄像头
- 在Android程序中调用摄像头功能
- 在ubuntu下开启摄像头
- WP7 开发学习(2):在WP7中使用网络请求
- 在Windows程序中,开启控制台
- VisualBasic实现在程序中开启网页
- android 在程序中开启GPS功能
- android 在程序中开启GPS功能
- 直接在程序中更改显示模式
- 直接在Cocoa程序中执行AppleScript
- 在C#中直接调用相关程序
- 在Eclipse中直接运行Mapreduce程序
- wp7程序在Panorama页面使用applicationBar
- 在java程序中开启另一个java程序
- 在J2ME中使用MMAPI开发摄像头程序
- 在非MFC程序中引用CString
- javascript图片预加载技术
- javax.naming.NoInitialContextException解决
- C#多线程|匿名委托传参数|测试您的网站能承受的压力|附源代码--升级版
- Spring学习文档_AOP
- 回调与并发: 通过实例剖析WCF基于ConcurrencyMode.Reentrant模式下的并发控制机制
- wp7在程序中直接开启摄像头(非选择器)
- android导航条的制作
- 《算法导论》系列课后思考题之-第三章《函数的增长》(下)
- 在Windows使用NodeJs和Web Framework:Express开发网站
- 【python】python的方法覆盖
- 怎么样把百度搜索引入自己的网站JS实现(附源代码)
- 常用Oracle DBA 查询
- 最长上升子序列
- 发布网站,出现:分析器错误信息: 发现不明确的匹配