Graphics异常,报内存不足

原因:很有可能是因为图片大小导致的,需要通过PS修改一下图片大小

 string imageName = sourceImageTb.Substring(sourceImageTb.LastIndexOf('/'));
                    string imageSourcePath = Path.Combine(Config_MCDWX.Instance.Exam_CertificateTemplateDirectory + imageName);
                    LogHelper.Debug(imageSourcePath);
                    System.Drawing.Bitmap imgSrc = new Bitmap(imageSourcePath);// System.Drawing.Bitmap.FromFile(imageSourcePath);
                    // StreamReader sr = new StreamReader(postedStream, System.Text.Encoding.UTF8);
                    using (Graphics g = Graphics.FromImage(imgSrc))
                    {
                        g.DrawImage(imgSrc, 0, 0, imgSrc.Width, imgSrc.Height);
                        string fontFamily = "Microsoft YaHei";
                        if (entityEmail.CurrentLanguage == -1)
                        {
                            fontFamily = "Calibri";
                        }
                        using (Font f = new Font(fontFamily, 20, FontStyle.Bold))
                        {
                            using (Brush b = new SolidBrush(Color.FromArgb(0, 0, 0)))
                            {
                                // g.DrawString(title, f, b, entityEmail.CurrentLanguage == 1 ? 990 : 330, 180);
                                int nCurrentLen = 465;
                                if (title.Length == 2)
                                    nCurrentLen = nCurrentLen + 10;
                                else if (title.Length == 4)
                                    nCurrentLen = nCurrentLen - 10;
                                g.DrawString(title, f, b, entityEmail.CurrentLanguage == 1 ? nCurrentLen : 465, entityEmail.CurrentLanguage == 1 ? 270 : 270);
                                Font f1 = new Font("Calibri", 20);
                                g.DrawString(date, f1, b, entityEmail.CurrentLanguage == 1 ? 225 : 225, entityEmail.CurrentLanguage == 1 ? 570 : 570);
                                // g.DrawString(date, f1, b, 130, 495);
                            }

                        }
                        g.Dispose();
                    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值