C# 生成二维码时出错
目前我正在从事ASP.NET项目,该项目要求生成带有嵌入链接的二维码。我收到以下错误:-C# 生成二维码时出错,c#,asp.net,image,qr-code,C#,Asp.net,Image,Qr Code,目前我正在从事ASP.NET项目,该项目要求生成带有嵌入链接的二维码。我收到以下错误:- A generic error occurred in GDI+. 我使用的代码:- Bitmap img = encoder.Encode("http://localhost)/GFile/%20" + lblId.Text); img.Save("~/QRimage/" + txtFName.Text + ".jpg", ImageFormat.Jpeg); QRIma
A generic error occurred in GDI+.
我使用的代码:-
Bitmap img = encoder.Encode("http://localhost)/GFile/%20" + lblId.Text);
img.Save("~/QRimage/" + txtFName.Text + ".jpg", ImageFormat.Jpeg);
QRImage.ImageUrl = txtFName.Text + ".jpg";
堆栈跟踪:-
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +461268
System.Drawing.Image.Save(String filename, ImageFormat format) +69
ViewResume.btnQRcode_Click(Object sender, EventArgs e) in
c:\Users\Samba\Desktop\Den\ViewResume.aspx.cs:341
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.
RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String
eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +5563
您的括号有误
更改此项:
Bitmap img=encoder.Encode(“http://localhost)/GFile/%20“+lblId.Text
)
为此:
Bitmap img = encoder.Encode("http://localhost/GFile/%20" + lblId.Text);
您好,错误显示在img.save上,编码器部件没有问题。@无误这是一种可能性,如果您的img位图链接到错误的路径,save函数将生成错误,因为它找不到您描述的路径。您是否尝试过按我描述的方式更改它?我尝试过更改路径,但仍然有相同的问题。您是否有保存img的正确权限?
txtFName.Text
Yes,txtFName.Text的值是多少,仅用于图像的命名目的。根据可用的答案,声明它与文件权限有关。但我还是不知道。嗨,我已经检查了其他解决方案,但仍然卡住了。希望有人能指导我,因为我没有在没有检查的情况下发布这个问题。