weixin_44042187 2018-12-18 12:56 采纳率: 0%
浏览 455

程序没有报错,但是一直显示正在运行,生成的二维码图片也无法保存到本地目录?

用webapi做一个生成二维码的接口,可是无法保存到本地,运行程序则是一直显示正在运行
代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Drawing;
using System.Drawing.Imaging;
using ZXing;
using ZXing.QrCode;
using ZXing.Common;
using ZXing.QrCode.Internal;
using MvcApplication.Models;


namespace MvcApplication.Controllers
{
public class BarCodeController : Controller
{


/// <summary>
/// 生成二维码图片
/// </summary>
/// <param name="contents">要生成二维码包含的信息</param>
/// <param name="width">生成的二维码宽度(默认300像素)</param>
/// <param name="height">生成的二维码高度(默认300像素)</param>
/// <returns>二维码图片</returns>
public static Bitmap GeneratorQrImage(string msg, int width = 300, int height = 300)
{
msg = "a";
if (string.IsNullOrEmpty(msg))
{
return null;
}
EncodingOptions options = null;
BarcodeWriter writer = null;
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = width,
Height = height,
ErrorCorrection = ErrorCorrectionLevel.H,
};
writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;


Bitmap bitmap = null;
try
{
bitmap = writer.Write(msg);
string filename = @"D:\" + msg + ".png";
bitmap.Save(filename, ImageFormat.Png);
}
catch (Exception ex)
{
Console.WriteLine("捕获异常");
}
finally
{
bitmap.Dispose();
}
return bitmap;
}
}
}
  • 写回答

1条回答 默认 最新

  • hxycsdn9159 2018-12-18 08:11
    关注

    看程序好像没问题,最起码你自己先调试一下,程序一直在运行中到底是卡到哪一句代码执行不下去了?

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作