string url = Config.GetInstance().SystemSetting.Url; //http://wsl2.plusbe.com/detail.aspx string str = url + "?qdid=" + qdid + "&id=" + id; string filename = "Product_" + id + "_Supp_"+qdid+".png"; // string path = System.Web.HttpContext.Current.Server.MapPath(SysConfig.ApplicationPath + "/ProductEwmPic/" + filename); // // string path = "ProductEwmPic"; string file = path + "\\Product" + id + ".png"; string url = getewm(str, file); // string pic = Ticket.ToQRCode(str, path); ByteMatrix byteMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, 350, 350); Bitmap bitmap = toBitmap(byteMatrix); ImageFormat format = ImageFormat.Png; string path = System.Web.HttpContext.Current.Request.MapPath("../../ProductEwmPic"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!System.IO.File.Exists(System.Web.HttpContext.Current.Request.MapPath("../../ProductEwmPic/" + filename))) { bitmap.Save(path + "/" + filename, format);//保存 } bitmap.Dispose(); string imgSrc = "ProductEwmPic/" + filename;// 底下是调用方法 public static Bitmap toBitmap(ByteMatrix matrix) { int width = matrix.Width; int height = matrix.Height; Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF")); } } return bmap; }
要正常使用它 需要网上下载一个 QRCodeProvider.dll 文件