基本信息
源码名称:调用和摄像头识别二维码
源码大小:0.97M
文件格式:.rar
开发语言:C#
更新时间:2013-05-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System; using System.Drawing; using System.Windows.Forms; using com.google.zxing; using COMMON = com.google.zxing.common; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); private void button1_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() != DialogResult.OK) { return; } Image img = Image.FromFile(this.openFileDialog1.FileName); Bitmap bmap; try { bmap = new Bitmap(img); } catch (System.IO.IOException ioe) { MessageBox.Show(ioe.ToString()); return; } if (bmap == null) { MessageBox.Show("Could not decode image"); return; } LuminanceSource source = new RGBLuminanceSource(bmap, bmap.Width, bmap.Height); com.google.zxing.BinaryBitmap bitmap = new com.google.zxing.BinaryBitmap(new COMMON.HybridBinarizer(source)); Result result; try { result = new MultiFormatReader().decode(bitmap); } catch (ReaderException re) { this.textBox1.Text = re.ToString(); return; } MessageBox.Show( result.Text); } private void button2_Click(object sender, EventArgs e) { SaveFileDialog sFD = new SaveFileDialog(); sFD.DefaultExt = "*.png|*.png"; sFD.AddExtension = true; try { if (sFD.ShowDialog() == DialogResult.OK) { string content = this.textBox1.Text; COMMON.ByteMatrix byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 350, 350); writeToFile(byteMatrix, System.Drawing.Imaging.ImageFormat.Png, sFD.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void writeToFile(COMMON.ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, string file) { Bitmap bmap = toBitmap(matrix); bmap.Save(file, format); pictureBox1.Image = bmap; } public Bitmap toBitmap(COMMON.ByteMatrix matrix) { int width = matrix.Width; int height = matrix.Height; Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int x = 0; x < width; x ) { for (int y = 0; y < height; y ) { bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF")); } } return bmap; } } }