using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Drawing;
using
System.Data;
using
System.Text;
using
System.Windows.Forms;
using
ThoughtWorks.QRCode.Codec;
using
ThoughtWorks.QRCode.Codec.Data;
namespace
二维码
{
public
partial
class
UC_From : UserControl
{
public
UC_From()
{
InitializeComponent();
}
string
filepath =
""
;
private
void
button1_Click(
object
sender, EventArgs e)
{
OpenFileDialog p =
new
OpenFileDialog();
p.Title =
"请选择二维码文件"
;
p.Filter =
"图片文件(*.jpg)|*.jpg"
;
p.Multiselect =
false
;
if
(p.ShowDialog() == DialogResult.OK)
{
filepath = p.FileName;
System.Threading.Thread t =
new
System.Threading.Thread(ss);
t.IsBackground =
true
;
t.Start();
}
}
private
void
ss()
{
if
(filepath !=
""
)
{
string
tt =
""
;
try
{
Invoke((EventHandler)
delegate
{
button1.Enabled =
false
;
button1.Text =
"Waiting!"
;
pictureBox1.Image =
new
Bitmap(filepath);
});
//pictureBox1.Size = new Size(new Bitmap(filepath).Size.Width, new Bitmap(filepath).Size.Height);
QRCodeDecoder qrDecoder =
new
QRCodeDecoder();
string
txtMsg = qrDecoder.decode(
new
QRCodeBitmapImage(
new
Bitmap(pictureBox1.Image)), Encoding.UTF8);
tt = txtMsg;
}
catch
{ tt =
"识别失败"
; }
Invoke((EventHandler)
delegate
{
textBox1.Text = tt;
button1.Enabled =
true
;
button1.Text =
"识别"
;
});
}
System.Threading.Thread.CurrentThread.Abort();
}
private
void
textBox1_KeyPress(
object
sender, KeyPressEventArgs e)
{
e.Handled =
true
;
}
}
}