创建QRCode图像时,实时服务器上出现GDI +错误

时间:2018-03-30 13:48:50

标签: c# asp.net model-view-controller

我是一名初创软件工程师。我试图在QR码中创建并保存一些信息。一切都在当地很好。但是当我将这个项目上传到实时服务器并对其进行测试时,它会给出一个例外。有一件事我确信,QR码会被创建,但是当将这个QR码保存为.png图像时,它会产生异常。请有人帮忙...... 任何帮助都感激不尽。

 public string CreateQRCode(StudentAndOrdersModel model)
    {
        //QR CODE DATA
        string informationInQRCode = "Student Name: " + model.StudentName + "Student ID: " + model.StudentID +
                                     "Course Name: " + model.CourseName + "OrderID:" + model.OrderID +
                                     "Total Cost:" + model.TotalCost;
        //QR CODE CREATION
        ZXing.BarcodeWriter w = new ZXing.BarcodeWriter();

        w.Options.Height = 200;
        w.Options.Width = 200;

        w.Format = ZXing.BarcodeFormat.QR_CODE;

        System.Drawing.Bitmap img = w.Write(informationInQRCode);


        string NameQRCode = QRCodeName();
        var MakeUrlString = Server.MapPath("~/Content/images/" + NameQRCode);
        //here is the exception problem. image is not beign saved on server.
        try
        {
            img.Save(MakeUrlString);
        }
        catch (Exception e)
        {
            return e.Message.ToString();
        }
        return NameQRCode;
    }
public string QRCodeName()
    {
        //CREATE RANDOM NAME
        int length = 10;
        string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        StringBuilder res = new StringBuilder();
        Random rnd = new Random();
        while (0 < length--)
        {
            res.Append(valid[rnd.Next(valid.Length)]);
        }
        string NameQRCode = "QRCode" + res.ToString() + ".png";
        return NameQRCode;
    }

这就是我得到的

  

GDI +中发生了一般性错误。

0 个答案:

没有答案