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; }
}
}
}
特别是解码,想了半天,结果在项目官网首页-_-!
好吧,简单一些
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; }
}
}
}
特别是解码,想了半天,结果在项目官网首页-_-!
相关文章推荐
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像
- .NET C#利用ZXing生成、识别二维码/条形码
- C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
- C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
- C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
- zxing二维码的生成与解码(C#)
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像 .
- C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(一)
- C#利用zxing.net生成二维码和条形码并实现打印的功能
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像
- C# 利用ZXing.Net来生成条形码和二维码
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像
- C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(一)
- zxing二维码的生成与解码(C#)
- [转]zxing二维码的生成与解码(C#)
- C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)
- C# 利用BarcodeLib.dll生成条形码(一维,zxing,QrCodeNet/dll二维码)
- C#利用Zxing.net生成二维码和条形码并实现打印的功能
- C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码
- C#利用ZXing.Net生成条形码和二维码