本文将介绍实现一个类似于微信扫一扫功能的UI界面,后续会再实现具体的识别二维码的功能。

实例使用的Win10 SDK Version是Windows 10 Anniversary Edition(10.0;Build 14393)。

简单的介绍UI布局

UI 布局采用 3*3 的Grid,扫描Foucs部分占据最中间,其他格子的背景色都是灰色并且设置了Opacity="0.2"。

扫描的动画采用的是线性动画DoubleAnimation,需要提到的是Storyboard.TargetName - 附加属性,要进行动画处理的对象的名称,Storyboard.TargetProperty - 附加属性,要进行动画处理的对象的属性。

此外还使用了CaptureElement来预览摄像头捕获的图像,具体如何实现会在下篇文章来介绍。

UI具体实现

  <Grid Background="#FF1D1D1D">
<Grid>
<CaptureElement x:Name="PreviewControl" Visibility="Collapsed" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Stretch="Fill" />
<Grid IsHitTestVisible="False">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Opacity="0.2" Background="LightGray" Grid.ColumnSpan="3"></Grid>
<Grid Opacity="0.2" Background="LightGray" Grid.Row="1"></Grid>
<Grid Opacity="0.2" Background="LightGray" Grid.Row="1" Grid.Column="2"></Grid>
<Grid Opacity="0.2" Background="LightGray" Grid.Row="2" Grid.ColumnSpan="3"></Grid>
<Grid x:Name="scanGrid" Grid.Row="1" Grid.Column="1" Opacity="1">
<Grid.Resources>
<Storyboard x:Name="scanStoryboard">
<DoubleAnimation x:Name="scanAnimation"
Storyboard.TargetName="scanLine"
Storyboard.TargetProperty="(Canvas.Top)"
Duration="0:0:2"
To="300"
RepeatBehavior="Forever"/>
</Storyboard>
</Grid.Resources>
<Border x:Name="leftTopBorder" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="White" />
<Border x:Name="rightTopBorder" HorizontalAlignment="Right" VerticalAlignment="Top" BorderBrush="White" />
<Border x:Name="leftBottomBorder" HorizontalAlignment="Left" VerticalAlignment="Bottom" BorderBrush="White" />
<Border x:Name="rightBottomBorder" HorizontalAlignment="Right" VerticalAlignment="Bottom" BorderBrush="White" />
<Canvas x:Name="scanCavas" Margin="10">
<Line Name="scanLine" X1="0" Y1="0" Y2="0" Stroke="Red" StrokeThickness="3" />
</Canvas>
</Grid>
</Grid>
</Grid>
</Grid>

UI自适应

由于在Win10里,App就像destop application可以随便改变窗口的大小,所以当窗口大小改变的时候我们需要重新计算Border的Width,Height,Line的宽度等等。

可以在Page的SizeChanged来实现我们的代码。

 const int borderThickness = ;

 private void InitFocusRec()
{
leftTopBorder.BorderThickness = new Thickness(borderThickness, borderThickness, , );
rightTopBorder.BorderThickness = new Thickness(, borderThickness, borderThickness, );
leftBottomBorder.BorderThickness = new Thickness(borderThickness, , , borderThickness);
rightBottomBorder.BorderThickness = new Thickness(, , borderThickness, borderThickness); var borderLength = ;
leftTopBorder.Width = leftTopBorder.Height = borderLength;
rightTopBorder.Width = rightTopBorder.Height = borderLength;
leftBottomBorder.Width = leftBottomBorder.Height = borderLength;
rightBottomBorder.Width = rightBottomBorder.Height = borderLength; var focusRecLength = Math.Min(ActualWidth / , ActualHeight / );
scanGrid.Width = scanGrid.Height = focusRecLength;
scanCavas.Width = scanCavas.Height = focusRecLength; scanStoryboard.Stop();
scanLine.X2 = scanCavas.Width - ;
scanAnimation.To = scanCavas.Height; scanStoryboard.Begin();
} private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
InitFocusRec();
}

预览效果图如下:

后续将介绍实现摄像头的预览功能。

How To Scan QRCode For UWP (1)的更多相关文章

  1. How To Scan QRCode For UWP (4)

    QR Code的全称是Quick Response Code,中文翻译为快速响应矩阵图码,有关它的简介可以查看维基百科. 我准备使用ZXing.Net来实现扫描二维码的功能,ZXing.Net在Cod ...

  2. How To Scan QRCode For UWP (3)

    这一节主要介绍如何去设置MediaCapture拍照的分辨率. MediaCapture 包含一个 VideoDeviceController对象,凭借它可以控制摄像头的很多设置,其中包括设置拍照的分 ...

  3. How To Scan QRCode For UWP (2)

    这篇随笔主要介绍照相预览功能,重要使用的是MediaCapture对象,MediaCapture对象还可以用来处理录音和录制视频,本文只讨论照相功能. 1:查找摄像头 后置摄像头优先,找不到后置摄像头 ...

  4. SWIFT Scan QRCode

    SWIFT中扫描QRCode代码如下,照着敲一次再看下API的注释应该就没问题了. import UIKit import Foundation import AVFoundation class V ...

  5. Python生成二维码脚本

    简单的记录下二维码生成和解析的Python代码 依赖下面三个包: PIL(图像处理包,安装:pip install PIL) qrcode(二维码生成包,安装:pip install qrcode) ...

  6. 初涉扫码登录:edusoho实现客户端扫码登录(简版)

    一.项目简介及需求 edusoho是一套商业版的在线教育平台,项目本身基于symfony2框架开发,现在有一款自己的APP,要求在不多修改edusoho自身代码的基础上,实现客户端对PC端扫码登录.不 ...

  7. 一次使用Python连接数据库生成二维码并安装为windows服务的工作任务

    最近有一个需求,在现有生产系统上的人员库中增加一个此人员关键信息的二维码,支持文字版和跳转版两种方式,与报表工具关联,可打印.以windows服务方式,定时检查,只要发现某人员没有此二维码信息,就生成 ...

  8. python库使用整理

    1. 环境搭建 l  Python安装包:www.python.org l  Microsoft Visual C++ Compiler for Python l  pip(get-pip.py):p ...

  9. AppCan移动应用开发平台新增9个超有用插件(内含演示样例代码)

    使用AppCan平台进行移动开发.你所须要具备的是Html5+CSS +JS前端语言基础.此外.Hybrid混合模式应用还需结合原生语言对功能模块进行封装,对于没有原生基础的开发人员,怎样实现App里 ...

随机推荐

  1. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  2. Win7 VS2013环境编译boost1_58_0

    备忘,发现好多不常用的东西不记笔记再想用要重新花时间找,所以试着开始记笔记,写入博客吧. 首先去官网下最新的版本 http://www.boost.org/ 写本文时boost最新版本为1_58_0, ...

  3. Methods to reduce the number of pipeline stages

    Several techniques have been proposed to reduce the number of pipeline stages. We categorize them in ...

  4. nullptr(c++11)

    1.概念 用字面值常量nullptr来初始化或赋值来得到空指针 2.c++11之前使用NULL或0 1)NULL是一个宏定义(预处理变量),定义在cstdlib中,其值就是0:对于预处理变量,预处理器 ...

  5. linux cp操作,每天学习一点

    指令名称:cp(copy)功能介绍:将一个文件复制至另一个文件,或将数个文件复制至另一目录. 语法格式: cp [options] source dest  cp [options] source.. ...

  6. 乌龙之Ignoring query to other database问题

    问题现象: [root@zxdb05 ~]# mysql -root -pEnter password: Welcome to the MySQL monitor.  Commands end wit ...

  7. Remote Debugging (3)

    use Eclipse| a Web application 创建一个简单的web项目 AServlet.java package cn.zno; import java.io.IOException ...

  8. Unicode和多字节的相互转换

    多字节转Unicode 四步: Step1 #include <iostream> #include "windows.h" using namespace std; ...

  9. 正则表达式Regular expressions

    根据某种匹配模式来寻找strings中的某些单词 举例:如果我们想要找到字符串The dog chased the cat中单词 the,我们可以使用下面的正则表达式: /the/gi 我们可以把这个 ...

  10. 标记化结构初始化语法 在结构体成员前加上小数点 如 “.open .write .close ”C99编译器 .

    今天在看串口驱动(四)的时候 有这样一个结构体初始化 我很不理解 如下: static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] ...