從井民全老師的blog中看到有寫到有關QRCode的操作後馬上著手練習,之後又在youtube看到一個作者用很簡潔的內容寫出了QRCode的操作,以下的是參考monsterhunter445後寫出的程式碼。與井民全老師的差別在於,monsterhunter445作者是載入了MessagingToolkit.QRCode.dll。
原始碼分享在下面:
此程式可依輸入的網址來編成QRCode
亦可載入QRCode之後解碼出網址
程式碼如下:
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.Drawing .Imaging ;
using MessagingToolkit.QRCode.Codec;
using MessagingToolkit.QRCode.Codec.Data;
namespace QRYoutube
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Create_Click(object sender, EventArgs e)
{
String URL= url.Text;
QRCodeEncoder encoder = new QRCodeEncoder();
//編碼成qrcode圖形
Bitmap qrcode = encoder.Encode(URL);
//將qrcode圖形放在picturebox
qrimage.Image = qrcode as Image ;
}
private void Save_Click(object sender, EventArgs e)
{ //儲存檔案
SaveFileDialog s = new SaveFileDialog();
s.Filter="PNG|*.png|JPEG|*.jpg|BMP|*.bmp";
if (s.ShowDialog() == DialogResult.OK)
{
qrimage.Image.Save(s.FileName);
}
}
private void Load_Click(object sender, EventArgs e)
{ //載入QRCode並在picturebox中顯示
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
qrimage.Image = Image.FromFile(op.FileName);
}
}
private void Extract_Click(object sender, EventArgs e)
{ //依載入的QRCode解碼出網址
QRCodeDecoder decoder = new QRCodeDecoder();
MessageBox.Show(decoder.decode(new QRCodeBitmapImage(qrimage.Image as Bitmap)));
}
}
}
沒有留言:
張貼留言