【发布时间】:2015-03-24 01:28:43
【问题描述】:
我正在创建二维码,并在上面使用了ZXing。但是在将位图保存到物理文件时会给我一个错误。
请帮忙。谢谢!
GDI+ 中出现一般错误
我也尝试过更改路径,但仍然出现错误。
protected void btnSaveInfo_Click(object sender, EventArgs e)
{
Bitmap img = new Bitmap(GenerateQR("HelloWorld"));
img.Save("QRCode.png"); //here gives me an error
}
public Bitmap GenerateQR(string text)
{
var bw = new ZXing.BarcodeWriter();
var encOptions = new ZXing.Common.EncodingOptions() { Width = 200, Height = 200, Margin = 0 };
bw.Options = encOptions;
bw.Format = ZXing.BarcodeFormat.QR_CODE;
var result = new Bitmap(bw.Write(text));
return result;
}
【问题讨论】:
-
我测试了你的代码,它对我来说运行良好。我对您的代码唯一要做的就是删除两个
new Bitmap(...)调用,因为bw.Write(text)和GenerateQR("HelloWorld")无论如何都返回Bitmap,但这不会影响程序。无论哪种方式都可以正常工作。
标签: c# asp.net image bitmap zxing