引用ZXing.dll
void Main(){
const string folder = @"F:\测试图片";
Bitmap bitMap = Generate2("1111111", 200, 120);
Image img = bitMap;
//保存
img.Save(Path.Combine(folder, "test.png"));
img.Dispose();
}
public static Bitmap Generate(string text, int width, int height)
{
BarcodeWriter writer = new BarcodeWriter();
//使用ITF 格式,不能被现在常用的支付宝、微信扫出来
//如果想生成可识别的可以使用 CODE_128 格式
//writer.Format = BarcodeFormat.ITF;
writer.Format = BarcodeFormat.CODE_39;
EncodingOptions options = new EncodingOptions()
{
Width = width,
Height = height,
Margin = 2
};
writer.Options = options;
Bitmap map = writer.Write(text);
return map;
}