mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-28 12:13:25 +08:00
项目结构调整
This commit is contained in:
9
Others/zxing.core/WPFDemo/App.xaml
Normal file
9
Others/zxing.core/WPFDemo/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="WPFDemo.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WPFDemo"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
17
Others/zxing.core/WPFDemo/App.xaml.cs
Normal file
17
Others/zxing.core/WPFDemo/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace WPFDemo
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
10
Others/zxing.core/WPFDemo/AssemblyInfo.cs
Normal file
10
Others/zxing.core/WPFDemo/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
64
Others/zxing.core/WPFDemo/MainWindow.xaml
Normal file
64
Others/zxing.core/WPFDemo/MainWindow.xaml
Normal file
@@ -0,0 +1,64 @@
|
||||
<Window x:Class="WPFDemo.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="MainWindow" Height="380" Width="531" ResizeMode="CanResize">
|
||||
<Grid>
|
||||
|
||||
<TabControl Height="Auto" Margin="0,1,0,0" Name="tabControl1" Width="Auto">
|
||||
<TabItem Header="Decode" Name="tabItemDecode">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="100" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox Grid.Column="0" Grid.Row="0" Height="23" HorizontalAlignment="Stretch" Margin="12,46,30,0" Name="txtBarcodeImageFile" VerticalAlignment="Top" Width="Auto" IsReadOnly="True" TextChanged="txtBarcodeImageFile_TextChanged" />
|
||||
<Button Grid.Column="0" Grid.Row="0" Content="..." Height="23" HorizontalAlignment="Right" Margin="465,46,0,0" Name="btnSelectFile" VerticalAlignment="Top" Width="26" Click="btnSelectFile_Click" />
|
||||
<Label Grid.Column="0" Grid.Row="0" Content="Barcode Image File" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" Width="124" />
|
||||
<Button Grid.Column="0" Grid.Row="0" Content="Decode" Height="23" HorizontalAlignment="Right" Margin="416,75,0,0" Name="btnDecode" VerticalAlignment="Top" Width="75" Click="btnDecode_Click" />
|
||||
<Grid Grid.Column="0" Grid.Row="1" >
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="350" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Image Grid.Column="0" Grid.Row="0" Height="Auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="imageBarcode" Stretch="None" VerticalAlignment="Top" Width="Auto" />
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="0,64,0,0" Name="txtBarcodeType" VerticalAlignment="Top" Width="265" IsReadOnly="True" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Content="Barcode Type" Height="28" HorizontalAlignment="Left" Margin="0,30,0,0" Name="label2" VerticalAlignment="Top" Width="95" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Content="Content" Height="28" HorizontalAlignment="Left" Margin="0,93,0,0" Name="label3" VerticalAlignment="Top" Width="95" />
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Height="97" HorizontalAlignment="Left" Margin="0,127,0,0" Name="txtBarcodeContent" VerticalAlignment="Top" Width="265" IsReadOnly="True" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Height="28" HorizontalAlignment="Left" Margin="0,0,0,0" Name="labDuration" VerticalAlignment="Top" Width="184" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Encode" Name="tabItemEncode">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="290" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Border BorderBrush="#202020" BorderThickness="1" CornerRadius="4">
|
||||
<Image Grid.Column="0" Grid.Row="0" Height="Auto" HorizontalAlignment="Stretch" Name="imageBarcodeEncoder" Stretch="Uniform" VerticalAlignment="Stretch" Width="Auto" />
|
||||
</Border>
|
||||
<Border BorderBrush="#202020" BorderThickness="1" CornerRadius="4">
|
||||
<Path Grid.Column="0" Grid.Row="0" Name="imageBarcodeEncoderGeometry" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="Black" Width="Auto" Height="Auto" />
|
||||
</Border>
|
||||
<Button Grid.Column="1" Grid.Row="0" Content="Encode" Height="23" HorizontalAlignment="Right" Margin="190,269,10,0" Name="btnEncode" VerticalAlignment="Top" Width="75" Click="btnEncode_Click" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Content="Barcode Type" Height="28" HorizontalAlignment="Right" Margin="0,6,180,0" Name="label4" VerticalAlignment="Top" Width="95" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Content="Content" Height="28" HorizontalAlignment="Right" Margin="0,132,180,0" Name="label5" VerticalAlignment="Top" Width="95" />
|
||||
<TextBox Grid.Column="1" Grid.Row="0" Height="97" HorizontalAlignment="Right" Margin="0,166,10,0" Name="txtBarcodeContentEncode" VerticalAlignment="Top" Width="265" />
|
||||
<ComboBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Right" Margin="0,40,10,0" Name="cmbEncoderType" VerticalAlignment="Top" Width="265" />
|
||||
<ComboBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Right" Margin="0,103,10,0" Name="cmbRendererType" VerticalAlignment="Top" Width="265" />
|
||||
<Label Grid.Column="1" Grid.Row="0" Content="Renderer Type" Height="28" HorizontalAlignment="Right" Margin="0,69,180,0" Name="label6" VerticalAlignment="Top" Width="95" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Window>
|
||||
134
Others/zxing.core/WPFDemo/MainWindow.xaml.cs
Normal file
134
Others/zxing.core/WPFDemo/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2012 ZXing.Net authors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
using Microsoft.Win32;
|
||||
using ZXing;
|
||||
|
||||
using BarcodeReader = ZXing.Presentation.BarcodeReader;
|
||||
using BarcodeWriter = ZXing.Presentation.BarcodeWriter;
|
||||
using BarcodeWriterGeometry = ZXing.Presentation.BarcodeWriterGeometry;
|
||||
|
||||
namespace WPFDemo
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly BarcodeReader reader = new BarcodeReader();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
foreach (var format in MultiFormatWriter.SupportedWriters)
|
||||
cmbEncoderType.Items.Add(format);
|
||||
cmbEncoderType.SelectedItem = BarcodeFormat.QR_CODE;
|
||||
|
||||
cmbRendererType.Items.Add("WriteableBitmap");
|
||||
cmbRendererType.Items.Add("XAML Geometry");
|
||||
cmbRendererType.SelectedItem = "WriteableBitmap";
|
||||
}
|
||||
|
||||
private void btnSelectFile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
Filter = "All documents (*.*)|*.*",
|
||||
FileName = txtBarcodeImageFile.Text
|
||||
};
|
||||
if (dlg.ShowDialog(this).GetValueOrDefault(false))
|
||||
{
|
||||
txtBarcodeImageFile.Text = dlg.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnDecode_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
var result = reader.Decode((BitmapSource)imageBarcode.Source);
|
||||
labDuration.Content = (DateTime.Now - start).Milliseconds + " ms";
|
||||
if (result != null)
|
||||
{
|
||||
txtBarcodeType.Text = result.BarcodeFormat.ToString();
|
||||
txtBarcodeContent.Text = result.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
txtBarcodeType.Text = "";
|
||||
txtBarcodeContent.Text = "No barcode found.";
|
||||
}
|
||||
}
|
||||
|
||||
private void txtBarcodeImageFile_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (File.Exists(txtBarcodeImageFile.Text))
|
||||
{
|
||||
imageBarcode.Source = new BitmapImage(new Uri(txtBarcodeImageFile.Text));
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEncode_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
imageBarcodeEncoder.Visibility = Visibility.Hidden;
|
||||
imageBarcodeEncoderGeometry.Visibility = Visibility.Hidden;
|
||||
|
||||
switch (cmbRendererType.SelectedItem.ToString())
|
||||
{
|
||||
case "WriteableBitmap":
|
||||
{
|
||||
var writer = new BarcodeWriter
|
||||
{
|
||||
Format = (BarcodeFormat)cmbEncoderType.SelectedItem,
|
||||
Options = new ZXing.Common.EncodingOptions
|
||||
{
|
||||
Height = (int)((FrameworkElement)imageBarcodeEncoder.Parent).ActualHeight,
|
||||
Width = (int)((FrameworkElement)imageBarcodeEncoder.Parent).ActualWidth,
|
||||
Margin = 0
|
||||
}
|
||||
};
|
||||
var image = writer.Write(txtBarcodeContentEncode.Text);
|
||||
imageBarcodeEncoder.Source = image;
|
||||
imageBarcodeEncoder.Visibility = Visibility.Visible;
|
||||
}
|
||||
break;
|
||||
case "XAML Geometry":
|
||||
{
|
||||
var writer = new BarcodeWriterGeometry
|
||||
{
|
||||
Format = (BarcodeFormat)cmbEncoderType.SelectedItem,
|
||||
Options = new ZXing.Common.EncodingOptions
|
||||
{
|
||||
Height = (int)((FrameworkElement)imageBarcodeEncoder.Parent).ActualHeight,
|
||||
Width = (int)((FrameworkElement)imageBarcodeEncoder.Parent).ActualWidth,
|
||||
Margin = 0
|
||||
}
|
||||
};
|
||||
var image = writer.Write(txtBarcodeContentEncode.Text);
|
||||
imageBarcodeEncoderGeometry.Data = image;
|
||||
imageBarcodeEncoderGeometry.Visibility = Visibility.Visible;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Others/zxing.core/WPFDemo/WPFDemo.csproj
Normal file
13
Others/zxing.core/WPFDemo/WPFDemo.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\zxing.core\zxing.core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user