netcore webapi 输出imges,在docker里面swagger报错

 

 

发现:service中有个webapi输出了:

public Bitmap GetLogoQRCode(string url, string logoPath, int pixel)
        {
            return QRCoderHelper.GetLogoQRCode(url, logoPath, pixel);
        }

在IIS里面正常,但是在docker里面就报错。

IIS里面swagger中显示该方法返回的是:

"System.Drawing.Bitmap"

-------------
暂时改为:

public FileResult GetPTQRCode(QRCoderDto dto)
        {
            try
            {
                var bitmap = QRCoderHelper.GetPTQRCode(dto.Url, dto.Pixel);
                MemoryStream ms = new MemoryStream();
                bitmap.Save(ms, ImageFormat.Jpeg);

                return new FileContentResult(ms.ToArray(), "image/png");
            }
            catch (Exception)
            {
                throw new UserFriendlyException("二维码生成异常,请检查");
            }
        }

然后在dockerfile中加入:

RUN  mv /etc/apt/sources.list /etc/apt/sources.list.bak
RUN  echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.list
RUN  echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
RUN  echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
RUN  echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
RUN apt-get update -y
RUN apt-get install libgdiplus

 

posted @ 2020-07-15 13:36  幸福安康  阅读(328)  评论(0编辑  收藏  举报