86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace dccdc.Selfhelp
|
|
{
|
|
public partial class TestCode : Form
|
|
{
|
|
public TestCode()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void aa()
|
|
{
|
|
extend.CallBack cb = m_callback;
|
|
byte[] info = new byte[1024];
|
|
int i = extend.Scan_QR(cb, (int)HSM_select.Scan_HSM, ref info[0], (int)QR_type.number);
|
|
if (-99 == i)
|
|
{
|
|
MessageBox.Show("程序未初始化");
|
|
}
|
|
else if (0 == i)
|
|
{
|
|
MessageBox.Show(System.Text.Encoding.UTF8.GetString(info));
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(i.ToString());
|
|
}
|
|
pictureBox1.Image = null;
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
extend.test(1, 2);
|
|
Thread t = new Thread(aa);
|
|
t.Start();
|
|
|
|
|
|
}
|
|
|
|
private void TestCode_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
private void m_callback(IntPtr data, int width, int height, int step)
|
|
{
|
|
try
|
|
{
|
|
int size = 2592 * 1944 * 3;
|
|
byte[] imgdata = new byte[size];
|
|
Marshal.Copy(data, imgdata, 0, size);
|
|
size = Marshal.SizeOf(imgdata[0]) * imgdata.Length;
|
|
IntPtr pnt = Marshal.AllocHGlobal(size);
|
|
try
|
|
{
|
|
Marshal.Copy(imgdata, 0, pnt, imgdata.Length);
|
|
Bitmap img = new Bitmap(width, height, step, System.Drawing.Imaging.PixelFormat.Format24bppRgb, data);
|
|
show((Bitmap)img.Clone());
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(pnt);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
public void show(Bitmap bm)
|
|
{
|
|
pictureBox1.Image = bm;
|
|
Application.DoEvents();
|
|
}
|
|
|
|
}
|
|
}
|