说明:DataSet设计时设置字段类型:
绑定数据到字段:
dr1["二维码1"] = GetImageByte("二维码测试数据", "ImageName");
主要执行方法:
/// <summary>
/// 获取图片字节码
/// </summary>
/// <param name="erweimaInfo">二维码包含的数据信息</param>
/// <param name="brzyid">图片名称(过渡用,生成完毕可自行删除)</param>
/// <returns></returns>
private byte[] GetImageByte(string erweimaInfo, string brzyid)
{
DotNetBarcode barCode = new DotNetBarcode();
barCode.Type = DotNetBarcode.Types.QRCode;
string path = @"D:\Image\Tool" + brzyid + ".png";
DotNetBarcode BarCode = new DotNetBarcode();
BarCode.Type = DotNetBarcode.Types.QRCode;
BarCode.QRSetTextType = DotNetBarcode.QRTextTypes.Binary;
BarCode.SaveFileType = DotNetBarcode.SaveFileTypes.Png;
BarCode.Save(erweimaInfo, path, 100, 100);
FileStream fs1 = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader br1 = new BinaryReader(fs1);
byte[] bt1 = br1.ReadBytes((int)fs1.Length);
br1.Close();
fs1.Close();
return bt1;
}
效果图: