您的位置:首页 > 编程语言 > C#

ZXing.Net生成二维码和解码二维码图像 C#

2014-05-05 00:04 501 查看
就是简单的一个读和一个写就行,网上没有看到写的简单的,我就补充一下吧。 引用需要的zxing.dll。

好吧,简单一些

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using ZXing;
using ZXing.QrCode;

namespace ZXingTest
{
class QRCodeUtil
{
//根据文字产生二维码
public static WriteableBitmap CreatQR(string QRCodeString)
{
try
{
WriteableBitmap wb = null;
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = 400,
Width = 400,
}
};
if (QRCodeString.Length > 0) wb = writer.Write(QRCodeString);
return wb;
}
catch (Exception) { return null; }
}

//根据图片解码二维码
public static string DecodeQRCode(WriteableBitmap sourceimage)
{
try
{
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// load a bitmap
var result = reader.Decode(sourceimage);
// do something with the result
if (result != null)
{
return result.Text;
}
else return null;
}
catch (Exception) { return null; }
}
}
}


特别是解码,想了半天,结果在项目官网首页-_-!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  二维码 zxing c#