Graphics异常,报内存不足

来源:互联网 发布:php 分销提成计算公式 编辑:程序博客网 时间:2024/05/16 05:42

原因:很有可能是因为图片大小导致的,需要通过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