qr二维码生成器,利用免费服务生成QR二维码

QR码越来越多的出现在了人们的日常生活中,比如 电影票、电子优惠券、甚至是电子机票。
你能想象这样一张图片包含多少信息吗?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Windows.Forms; namespace CreateQR { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// /// 产生QR码的地址 /// readonly string qrcreateurl = "http://www.qrstuff.com/generate.generate?type=TEXT&text={0}&foreground_color=000000"; private void btnSave_Click(object sender, EventArgs e) { //保存数据 SaveData(picData); } /// /// 保存数据 /// ///
private void SaveData(byte[] data) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PNG格式图片|*.png"; saveFileDialog1.Title = "图片保存"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { if (File.Exists(saveFileDialog1.FileName)) { File.Delete(saveFileDialog1.FileName); } using (FileStream fs = File.Create(saveFileDialog1.FileName)) { fs.Write(data, 0, data.Length); } } } /// /// 临时图片数据 /// private byte[] picData; private void btnCreate_Click(object sender, EventArgs e) { //下载 DownloadData(string.Format(qrcreateurl, string.IsNullOrEmpty(txtQR.Text) ? "无内容" : txtQR.Text), (_send, _e) => { picData = _e.Result; using (MemoryStream ms = new System.IO.MemoryStream()) { ms.Write(picData, 0, picData.Length); pictureBox.Image = Image.FromStream(ms); }; }); } /// /// 下载数据 /// ///
///
private void DownloadData(string url, DownloadDataCompletedEventHandler dceh) { using (WebClient webClient = new WebClient()) { webClient.DownloadDataAsync(new Uri(url)); webClient.DownloadDataCompleted += dceh; }; } } }
文章最下面有全部源码以及demo 的下载地址
点我下载Demo
汤晓华 QQ 1881597 MSN [email protected]
2011 05 22
Tags:  二维码在线生成 二维码生成 二维码生成器 qr二维码 qr二维码生成器

延伸阅读

最新评论

发表评论