dll只有在根目录下加载才会正确生成图片

master
wanggang 4 years ago
parent 74a333cba4
commit 3c26a51a05

@ -1,4 +1,5 @@
using System.Drawing.Imaging;
using Serilog;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text;
@ -16,8 +17,18 @@ public class CVRHelper : IDisposable
Task.Run(async () =>
{
while (!this._cts.IsCancellationRequested)
{
try
{
this.ScanCardReader();
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
}
await Task.Delay(700);
}
});
@ -53,31 +64,19 @@ public class CVRHelper : IDisposable
}
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
private IdCardModel Read()
{
try
{
var length = 40960;
//var imgData = new byte[length];
//CVRSDK.GetJpgData(ref imgData[0], ref length);
//var image = "data:image/jpeg;base64," + Convert.ToBase64String(imgData);
using var bmp = new ImageMagick.MagickImage(Path.Combine(AppContext.BaseDirectory, "zp.bmp"));
using var ms = new MemoryStream();
bmp.Write(ms, ImageMagick.MagickFormat.Jpeg);
var image = "data:image/jpeg;base64," + Convert.ToBase64String(ms.ToArray());
var imgData = new byte[length];
CVRSDK.GetBMPData(ref imgData[0], ref length);
var image = "data:image/jpeg;base64," + Convert.ToBase64String(imgData, 0, length);
//var file = Path.Combine(Path.GetTempPath(), "chinaidcard", "zp.bmp");
//using var bmp = new ImageMagick.MagickImage(file);
//using var ms = new MemoryStream();
//bmp.Write(ms, ImageMagick.MagickFormat.Jpeg);
//var image = "data:image/jpeg;base64," + Convert.ToBase64String(ms.ToArray());
byte[] name = new byte[128];
length = 128;
CVRSDK.GetPeopleName(ref name[0], ref length);
@ -158,7 +157,10 @@ public class CVRHelper : IDisposable
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
}
return null;
}

@ -146,6 +146,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
code = 1;
message = ex.Message;
}
@ -166,6 +170,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
code = 1;
message = ex.Message;
}
@ -187,6 +195,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
code = 1;
message = ex.Message;
}
@ -207,6 +219,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
code = 1;
message = ex.Message;
}
@ -226,6 +242,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
code = 1;
message = ex.Message;
}
@ -279,7 +299,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
this.toolStripStatusLabel1.Text = ex.Message;
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
}
}));
});
@ -300,9 +323,10 @@ namespace PhotoCollector
}
catch (Exception ex)
{
this.Text += ex.Message;
this.Text += ex.StackTrace;
this.Text += Environment.NewLine;
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
}
}));
});

@ -19,6 +19,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
@ -30,36 +31,30 @@
</ItemGroup>
<ItemGroup>
<None Update="x64\license.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\sdtapi.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\Termb.dll">
<Content Include="webview\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x64\WltRS.dll">
</Content>
</ItemGroup>
<ItemGroup>
<Compile Update="Program.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x86\license.dat">
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="license.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x86\sdtapi.dll">
<None Update="sdtapi.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x86\Termb.dll">
<None Update="Termb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="x86\WltRS.dll">
<None Update="WltRS.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="webview\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

@ -1,18 +1,13 @@
using Microsoft.Data.Sqlite;
using PhotoCollector.Data;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace PhotoCollector
{
internal static class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDllDirectory(string path);
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -34,22 +29,34 @@ namespace PhotoCollector
try
{
Log.Information("application start");
var path = Path.Combine(AppContext.BaseDirectory, IntPtr.Size == 8 ? "x64" : "x86");
Log.Information($"SetDllDirectory:{path}");
SetDllDirectory(path);
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
AppDbContext.Init();
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler((s, e) => MessageBox.Show(e.Exception.Message));
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) => MessageBox.Show(e.ExceptionObject.ToString()));
Application.ThreadException += new ThreadExceptionEventHandler((s, e) =>
{
Log.Error(e.Exception.ToString());
#if DEBUG
MessageBox.Show(e.Exception.ToString());
#endif
});
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) =>
{
Log.Error(e.ExceptionObject.ToString());
#if DEBUG
MessageBox.Show(e.ExceptionObject.ToString());
#endif
});
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
Log.Information("application exit");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Log.Error(ex.ToString());
#if DEBUG
MessageBox.Show(ex.Message);
#endif
}
finally
{

@ -6,10 +6,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0-windows\publish\win-x86\</PublishDir>
<PublishDir>bin\Release\net6.0-windows\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0-windows</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>

Binary file not shown.

Binary file not shown.

@ -1 +0,0 @@
0744e088ca453d89bdc6eb2ff732c9b161033baeb37cc56d9f77d8694bd1eb0d05f4cebc33fe3b148820af747e4377bb00f20e536674a66fa7380590ca7792c99e14b055abc74aae687aaf40aff3a1966db4a8e29e1fad4279dec343e78248a43a6a2d5c1ce792ddc59d969b722d6dc81211b36242c7ff707b31bc6a8a3c349541c0eed86da73a2cee520a8daf3803db56d0d4dc3ab2c78117f9956a9beb7fab1bdc9ad1864f6b20975fb31f4e5d8c57a0bbb5576e282bfbb4fdf9ee03d8506e3186da4f4f273043db8c3b5837e430c25a98fedbc6735368b9068e1ea84bd065e988565bb076061c3ca34741521516a6eb3057712ada68db90dcfc01738b2718aca9b5fc9186c033236a82e08837678abb4b661f82319239a047ec9f4ce27c0fe3b0a03bda9da311f6ab913fbf944af732b1d6efb61af8ad510f06011c96f7d3f466be1e7304d73d1e2c1f66e072e874b8294de9ae84c3330bfbf12ec9f0c2eb4993b8b04403833f04b6d25bd41a6989b5da7314522a1a5336d4562e3d3802df48ff35f635e1cfa00f10522881d4f4be9172f2788b5326963a62dc0a5eb6e2385b71defa2fe8e4e7a63248d5d1e8b19cb4d36f1d3f480f83806d2cc916b2887de9b25bc3185eea9c33585c68ab9dc9aa8667950c5752fca36ebded734c731c365a8b5359da8c08481dd535ebf63c647070f6094cbcb7157c6d19bb11e842c7eb15c16ec55bba6772cc437c659c0da977d84776e554bf8498e64b65aad167b025841f550e85302fa2a86ad8df8458c146272382e009b46e7f3f196b46f12a016b0e6cb0313e3587601911f2609665d466c652d544c2dcfeb7e24c83ed2fd2df461b6f265870129735870271f0ba7b095d1b9c1819678159ca35ac54a873a9743d13f16068021088a85a03fe97d8e488b590c9f367dfe9aa40a200aa7ea5f5e8d85fba0677dc758242fadd415ed8e67af58ca00d37145c179f8f12c378aeff639f6592bf8ae689ac89cf58e14ca2cacaa677ea0f90ed24c87166a8b19d740f0c1b8e4133ab08962f07423b876a1fd8564fb86fa07b5288e63d8e8bf8f5e06d0bd3428e0be12ae23344b950dabf35579078b9f769ff2bcf998c6f834188da60314fea43ef3534b6dfc79d5d8353cd91dcaae14a1224604208e57157345f4b31aed3ec2686ad0e5a5b18572b292ed0cc636b982f42f2da295cd0fcd178811929a1b5b2007954a016d0bf4d82755924514c464670a1727fccbcd578b7b6f62e8e8baea2986f2fd3326644e9290fdbb368c0c053d3d8ab3872517d4dd295c770a8938c26b811488d31443092ea9ebc6358e76328218fa5ee64434fe3eabefbc9c1e2d6a52607a6b7a9930baf8bca041e6be8b62b216d6987ebb9d4a3c7d89a201f9f1487abf8513a947a5baad53dbccbe73441c59d1bfeed4ddb92f3308cad5c0bf3cf

Binary file not shown.

@ -87,7 +87,7 @@
<img id="idCard" width="102" height="126" alt="" />
<script>
var appBasePath = navigator.userAgent.split('|')[1];
window.chrome.webview.postMessage({ command: "setStatus", message: `app at ${appBasePath}` });
//window.chrome.webview.postMessage({ command: "setStatus", message: `start at ${appBasePath}` });
function onIdCardRead(card) {
var img = document.getElementById('idCard');

Loading…
Cancel
Save