株洲能建网站的有哪些,小程序一个页面多少钱,wordpress聚合广告平台,个人能接做网站的活么刚刚做过这类开发#xff0c;所以就先献丑了#xff0c;当然所贴上的源代码都是经过验证过的#xff0c;已经执行成功了#xff0c;希望能够给大家一些借鉴#xff1a; 以下是metro UI代码#xff1a; Pagex:ClassCamera.MainPagexmlnshttp://sche… 刚刚做过这类开发所以就先献丑了当然所贴上的源代码都是经过验证过的已经执行成功了希望能够给大家一些借鉴 以下是metro UI代码 Pagex:ClassCamera.MainPagexmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localusing:Cameraxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006mc:IgnorabledGrid Background{ThemeResource ApplicationPageBackgroundThemeBrush}Button x:NamebtnCamera Content打开摄像头 HorizontalAlignmentLeft Margin48,259,0,0 VerticalAlignmentTop ClickbtnCamera_Click Height45/Image x:Nameimg1 HorizontalAlignmentLeft Height609 Margin240,78,0,0 VerticalAlignmentTop Width718 StretchFill/Button x:NamebtnSave Content保存图片 HorizontalAlignmentLeft Margin48,369,0,0 VerticalAlignmentTop Height44 ClickbtnSave_Click//Grid
/Page显示的界面事实上非常easy可是这不重要功能才是基本的以下贴上基本的开发代码 using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Media.Capture;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage.Streams;// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId234238/** * 作者李天鹏* 功能调用PC上自带的camera实现拍照的功能并保存在对应的目录下* */
namespace Camera
{/// summary/// An empty page that can be used on its own or navigated to within a Frame./// /summarypublic sealed partial class MainPage : Page{private StorageFile file null;public MainPage(){this.InitializeComponent();}private async void btnCamera_Click(object sender, RoutedEventArgs e){CameraCaptureUI dialog new CameraCaptureUI();dialog.PhotoSettings.CroppedAspectRatio new Size(16, 9);file await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);if (file ! null){BitmapImage bitmapImage new BitmapImage();using (IRandomAccessStream fileStream await file.OpenAsync(FileAccessMode.Read)){bitmapImage.SetSource(fileStream);}img1.Source bitmapImage;}}private async void btnSave_Click(object sender, RoutedEventArgs e){if (img1.Source null)return;else{FileSavePicker picker new FileSavePicker();picker.CommitButtonText 保存;picker.SuggestedFileName hello;picker.FileTypeChoices.Add(图片,new string[]{.jpg,.jpeg,.bmp,.png});picker.SuggestedStartLocation PickerLocationId.PicturesLibrary;StorageFile filePath await picker.PickSaveFileAsync();if (filePath ! null){//打开通过摄像头拍摄的照片并返回流以流的形式读取文件var streamRandom await file.OpenAsync(FileAccessMode.Read);//将拍摄的照片以流的形式读取到缓冲区IBuffer buffer RandomAccessStreamToBuffer(streamRandom);//将缓冲区内容写入对应的目录中await FileIO.WriteBufferAsync(filePath, buffer);}}}//将图片写入到缓冲区private IBuffer RandomAccessStreamToBuffer(IRandomAccessStream randomstream){Stream stream WindowsRuntimeStreamExtensions.AsStreamForRead(randomstream.GetInputStreamAt(0));MemoryStream memoryStream new MemoryStream();if (stream ! null){byte[] bytes ConvertStreamTobyte(stream); //将流转化为字节型数组if (bytes ! null){var binaryWriter new BinaryWriter(memoryStream);binaryWriter.Write(bytes);}}IBuffer buffer WindowsRuntimeBufferExtensions.GetWindowsRuntimeBuffer(memoryStream, 0, (int)memoryStream.Length);return buffer;}//将流转换成二进制public static byte[] ConvertStreamTobyte(Stream input){byte[] buffer new byte[16 * 1024];using (MemoryStream ms new MemoryStream()){int read;while ((read input.Read(buffer, 0, buffer.Length)) 0){ms.Write(buffer, 0, read);}return ms.ToArray();}}}
}可是这还不够假设须要调用camera还须要一些权限应该在Package.appxmanifest里面改动权限 改动例如以下仅仅要勾上webcam即可了。 源代码下载 http://download.csdn.net/detail/litianpeng1991/7548065 转载于:https://www.cnblogs.com/mengfanrong/p/4069015.html