无法在ASP.NET C#项目中保存条形码生成的图像
发布时间:2020-12-16 09:49:48 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试使用System.Drawing.Save()保存图像,并且我一直收到无效参数异常. 有人可以看看我的代码并告诉我我做错了什么. 这是生成条形码图像的代码. public class BarcodeHelper { Font barcodeFont; public BarcodeHelper() { PrivateFontCollection fonts
我正在尝试使用System.Drawing.Save()保存图像,并且我一直收到无效参数异常.
有人可以看看我的代码并告诉我我做错了什么. 这是生成条形码图像的代码. public class BarcodeHelper { Font barcodeFont; public BarcodeHelper() { PrivateFontCollection fonts; FontFamily family = LoadFontFamily("~/../fonts/Code128bWin.ttf",out fonts); barcodeFont = new Font(family,20.0f); // when done: barcodeFont.Dispose(); family.Dispose(); family.Dispose(); } public FontFamily LoadFontFamily(string fileName,out PrivateFontCollection fontCollection) { fontCollection = new PrivateFontCollection(); fontCollection.AddFontFile(fileName); return fontCollection.Families[0]; } public Image GenerateBarcode(string barcodeText) { Image barcodeImage; using (barcodeImage = Image.FromFile(@"C:UsersAdministratorDesktopYodelShippingYodelShippingimagesbarcode.bmp")) { using (Graphics g = Graphics.FromImage(barcodeImage)) { g.DrawString(barcodeText,new Font(barcodeFont,FontStyle.Bold),Brushes.Black,barcodeImage.Height /2,barcodeImage.Width / 2); } } return barcodeImage; } } 这是我调用代码来创建和保存条形码图像的地方.我在调用Save()方法时遇到异常. System.Drawing.Image img = barcodeHelper.GenerateBarcode("2lgbub51aj+01000002"); img.Save("~/images/barcode.png"); 解决方法protected void Button1_Click(object sender,EventArgs e) { try { Barcode barcode = new Barcode(); BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE93; BarcodeLib.SaveTypes y = SaveTypes.JPG; barcode.Encode(type,"12344"); barcode.SaveImage(Server.MapPath("~/Barcodeabc.jpg"),y); Label1.Text = "Image Saved successfully"; } catch (Exception EE) { EE.ToString(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core – 我需要在ASP.NET Core for Cache中调用Add
- asp.net – 您使用什么工具来提高编码效率和整体效率
- ASP.NET MVC,GridViews,Calendars等的UI控件
- 禁用并选择asp.net mvc Html.RadioButtonFor
- 什么是链接服务器的ASP.NET连接字符串格式?
- asp.net – Web.Config可能“不可读”
- asp.net – 通配符HttpHandler不处理静态文件
- asp.net-mvc – Elmah.MVC在IIS Express下工作但不是IIS 7.
- 可能在ASP.Net页面中引发404错误?
- ASP.NET(C#)应用程序配置文件app.config/web.config的增、删
推荐文章
站长推荐
- ASP.NET MVC:如果url与当前url匹配,则将选定的C
- B/S(Web)实时通讯解决方案
- asp.net-core – 使用IdentityServer 4和WS-Fede
- asp.net-mvc – 使用MVC使用List填充@ Html.Drop
- asp.net – 可以承受1000个并发用户的Web服务,响
- asp.net – 冻结标题,滚动GridView
- asp.net-mvc – WebApi Action过滤器调用两次
- asp.net – 从C#代码增加Http Runtime MaxReques
- asp.net – 在web.config中添加程序集引用
- Linq与ASP.NET MVC 3中的MySQL数据库,将DateTime
热点阅读