print image

WPF打印二维码和条形码

北慕城南 提交于 2020-08-11 18:08:57
使用ZXing.net生成二维码和一维码图片,再使用PrintDocument打印图片 具体代码: private string GenerateBarCodeImage( string barCode, int width, int height, BarcodeFormat format) { BarcodeWriter writer = new BarcodeWriter { Format = format }; QrCodeEncodingOptions options = new QrCodeEncodingOptions(); // 设置内容编码 options.CharacterSet = " UTF-8 " ; // 设置二维码的宽度和高度 options.Width = width; options.Height = height; // 设置二维码的边距,单位不是固定像素 options.Margin = 1 ; writer.Options = options; string fileName = _printImageDirectory + Guid.NewGuid().ToString(); Bitmap map = writer.Write(barCode); map.Save(fileName, ImageFormat.Png); map