This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dec84c
commit 9c2da01
Showing
10 changed files
with
14,935 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("WinRTBarcodeReader.UW")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("WinRTBarcodeReader.UW")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: ComVisible(false)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* | ||
* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
namespace WinRTBarcodeReader | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Windows.Foundation; | ||
using Windows.Graphics.Imaging; | ||
using Windows.Media.Capture; | ||
using Windows.Media.MediaProperties; | ||
using Windows.Storage.Streams; | ||
|
||
using ZXing; | ||
|
||
/// <summary> | ||
/// Defines the Reader type, that perform barcode search asynchronously. | ||
/// </summary> | ||
public sealed class Reader | ||
{ | ||
#region Private fields | ||
|
||
/// <summary> | ||
/// Data reader, used to create bitmap array. | ||
/// </summary> | ||
private BarcodeReader barcodeReader; | ||
|
||
/// <summary> | ||
/// The cancel search flag. | ||
/// </summary> | ||
private CancellationTokenSource cancelSearch; | ||
|
||
/// <summary> | ||
/// MediaCapture instance, used for barcode search. | ||
/// </summary> | ||
private MediaCapture capture; | ||
|
||
/// <summary> | ||
/// Encoding properties for mediaCapture object. | ||
/// </summary> | ||
private ImageEncodingProperties encodingProps; | ||
|
||
/// <summary> | ||
/// Flag that indicates successful barcode search. | ||
/// </summary> | ||
private bool barcodeFoundOrCancelled; | ||
|
||
/// <summary> | ||
/// Image stream for MediaCapture content. | ||
/// </summary> | ||
private InMemoryRandomAccessStream imageStream; | ||
|
||
#endregion | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Reader" /> class. | ||
/// </summary> | ||
/// <param name="capture">MediaCapture instance.</param> | ||
/// <param name="width">Capture frame width.</param> | ||
/// <param name="height">Capture frame height.</param> | ||
public void Init(MediaCapture capture, uint width, uint height) | ||
{ | ||
this.capture = capture; | ||
encodingProps = ImageEncodingProperties.CreateJpeg(); | ||
encodingProps.Width = width; | ||
encodingProps.Height = height; | ||
|
||
barcodeReader = new BarcodeReader {Options = {TryHarder = true}}; | ||
cancelSearch = new CancellationTokenSource(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Public methods | ||
|
||
/// <summary> | ||
/// Perform async MediaCapture analysis and searches for barcode. | ||
/// </summary> | ||
/// <returns>IAsyncOperation object</returns> | ||
public IAsyncOperation<Result> ReadCode() | ||
{ | ||
return this.Read().AsAsyncOperation(); | ||
} | ||
|
||
/// <summary> | ||
/// Send signal to stop barcode search. | ||
/// </summary> | ||
public void Stop() | ||
{ | ||
this.cancelSearch.Cancel(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Private methods | ||
|
||
/// <summary> | ||
/// Perform async MediaCapture analysis and searches for barcode. | ||
/// </summary> | ||
/// <returns>Task object</returns> | ||
private async Task<Result> Read() | ||
{ | ||
Result result = null; | ||
try | ||
{ | ||
while (result == null) | ||
{ | ||
result = await GetCameraImage(cancelSearch.Token); | ||
} | ||
} | ||
catch (OperationCanceledException) { } | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Perform image capture from mediaCapture object | ||
/// </summary> | ||
/// <param name="cancelToken"> | ||
/// The cancel Token. | ||
/// </param> | ||
/// <returns> | ||
/// Decoded barcode string. | ||
/// </returns> | ||
private async Task<Result> GetCameraImage(CancellationToken cancelToken) | ||
{ | ||
if (cancelToken.IsCancellationRequested) | ||
{ | ||
throw new OperationCanceledException(cancelToken); | ||
} | ||
|
||
imageStream = new InMemoryRandomAccessStream(); | ||
|
||
await capture.CapturePhotoToStreamAsync(encodingProps, imageStream); | ||
await imageStream.FlushAsync(); | ||
|
||
var decoder = await BitmapDecoder.CreateAsync(imageStream); | ||
|
||
byte[] pixels = | ||
(await | ||
decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, | ||
BitmapAlphaMode.Ignore, | ||
new BitmapTransform(), | ||
ExifOrientationMode.IgnoreExifOrientation, | ||
ColorManagementMode.DoNotColorManage)).DetachPixelData(); | ||
|
||
const BitmapFormat format = BitmapFormat.RGB32; | ||
|
||
imageStream.Dispose(); | ||
|
||
var result = | ||
await | ||
Task.Run( | ||
() => barcodeReader.Decode(pixels, (int) decoder.PixelWidth, (int) decoder.PixelHeight, format), | ||
cancelToken); | ||
|
||
return result; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{4FC8299B-F4B7-46E8-AC55-10111C79C94A}</ProjectGuid> | ||
<OutputType>winmdobj</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>WinRTBarcodeReader</RootNamespace> | ||
<AssemblyName>WinRTBarcodeReader</AssemblyName> | ||
<DefaultLanguage>en-US</DefaultLanguage> | ||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> | ||
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion> | ||
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion> | ||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<AllowCrossPlatformRetargeting>false</AllowCrossPlatformRetargeting> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'"> | ||
<PlatformTarget>ARM</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\ARM\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>ARM</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'"> | ||
<PlatformTarget>ARM</PlatformTarget> | ||
<OutputPath>bin\ARM\Release\</OutputPath> | ||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>ARM</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\x64\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<OutputPath>bin\x64\Release\</OutputPath> | ||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\x86\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<OutputPath>bin\x86\Release\</OutputPath> | ||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<NoWarn>;2008</NoWarn> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<UseVSHostingProcess>false</UseVSHostingProcess> | ||
<ErrorReport>prompt</ErrorReport> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included --> | ||
<None Include="project.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Reader.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Condition="'$(Platform)'=='Any CPU'" Include="ZXing"> | ||
<HintPath>ANY\ZXing.winmd</HintPath> | ||
</Reference> | ||
<Reference Condition="'$(Platform)'=='x86'" Include="ZXing"> | ||
<HintPath>x86\ZXing.winmd</HintPath> | ||
</Reference> | ||
<Reference Condition="'$(Platform)'=='x64'" Include="ZXing"> | ||
<HintPath>x64\ZXing.winmd</HintPath> | ||
</Reference> | ||
<Reference Condition="'$(Platform)'=='ARM'" Include="ZXing"> | ||
<HintPath>ARM\ZXing.winmd</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' "> | ||
<VisualStudioVersion>14.0</VisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"dependencies": { | ||
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0" | ||
}, | ||
"frameworks": { | ||
"uap10.0": {} | ||
}, | ||
"runtimes": { | ||
"win10-arm": {}, | ||
"win10-arm-aot": {}, | ||
"win10-x86": {}, | ||
"win10-x86-aot": {}, | ||
"win10-x64": {}, | ||
"win10-x64-aot": {} | ||
} | ||
} |
Oops, something went wrong.