C#生成条形码
首先需要引用zxing.dll
public void getBarCode(HttpContext context) { int width = DTRequest.GetFormInt("width");长 int height = DTRequest.GetFormInt("height");宽 string order_no = DTRequest.GetFormString("order_no");订单号 try { QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.DisableECI = true; options.CharacterSet = "UTF-8"; options.Width = width; options.Height = height; BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.CODE_128; writer.Options = options; Bitmap bitmap = writer.Write(order_no);///这里显示订单号 writer.Write("1234566"); string upLoadPath = GetUpLoadPath(); //上传目录相对路径 string fullUpLoadPath = Utils.GetMapPath(upLoadPath); //上传目录的物理路径 if (!Directory.Exists(fullUpLoadPath)) { Directory.CreateDirectory(fullUpLoadPath); } string newFileName = Utils.GetRamCode()+".jpg"; //随机生成新的文件名 string newFilePath = upLoadPath + newFileName; //上传后的路径 string url = newFilePath; bitmap.Save(fullUpLoadPath + newFileName); //保存在本地文件夹 bitmap.Dispose(); context.Response.Write("{\"status\":1, \"msg\":\"" + url + "\"}"); } catch(Exception e){ context.Response.Write("{\"status\":0, \"msg\":\"" + e.ToString() + "\"}"); } }
分类:
后端 / 后端开发分享
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具