最近在產生QR code時發現了一個不錯的open source,
就是 ZXing.Net
它可以支援 .net2.0, 3.5, 4.0, 4.5, 而且又是免費的,
程式碼也非常簡單喔!
網路上有很多分享都是 using com.zxing,好像在現在新的版本已經不適用了
編譯環境:
windows7 64bit
.Net Framework 4.5
visual studio 2012 express
ZXing.Net.0.12.0.0
1.下載 ZXing.Net
2.把DLL加到專案中
依造自己的 .Net Framework 來選擇 DLL
3.Code
// Created by vince
// Copyright (c) 2013年 vince. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing; // for BarcodeWriter
using ZXing.QrCode; // for QRCode Engine
namespace qrcode_tutorial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var writer = new BarcodeWriter //dll裡面可以看到屬性
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions //設定大小
{
Height = 300,
Width = 300,
}
};
pictureBox1.Image = writer.Write(textBox1.Text); //轉QRcode的文字
}
}
}
4.執行結果


沒有留言:
張貼留言