当前位置: 代码迷 >> C# >> ,C#GDI+,生成图片文字不清晰
  详细解决方案

,C#GDI+,生成图片文字不清晰

热度:698   发布时间:2016-05-05 03:44:28.0
求助,C#,GDI+,生成图片文字不清晰
bitmap = new Bitmap(width, height);
                        graphics = Graphics.FromImage(bitmap);
                        graphics.DrawString("哈喽哈喽哈喽", new Font("微软雅黑", 20),
                            Brushes.Black, new PointF(stringX, stringY));
                        graphics.Flush();
                        bitmap.Save(dir + i.ToString() + ".png",
                            System.Drawing.Imaging.ImageFormat.Png);
                        graphics.Dispose();
                        bitmap.Dispose();


为啥会出现加粗效果啊,怎么能显示出正常的字呢?
------解决思路----------------------
微软雅黑 就是这么粗吧。
你改用宋体就不一样了。
------解决思路----------------------
你系统里有微软雅黑么?
------解决思路----------------------
微软雅黑必须要下载到系统字体里面,才可以显示出来!
------解决思路----------------------
Graphics.SmoothingMode设置下
https://msdn.microsoft.com/zh-cn/library/system.drawing.graphics.smoothingmode.aspx
------解决思路----------------------
new Font("微软雅黑", 20, FontStyle.Regular)
------解决思路----------------------
 graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;

这个调整下。
------解决思路----------------------
       Bitmap bmp = new Bitmap(300, 300);
            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(Brushes.Aqua, new Rectangle()
            {
                X = 0,
                Y = 0,
                Height = 300,
                Width = 300
            });
            g.DrawString("哈喽哈喽哈喽", new Font("宋体", 20), Brushes.Black, new PointF()
            {
                X = 0,
                Y = 0
            });
            bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
------解决思路----------------------

//BaseFont bfHei = BaseFont.createFont(@"c:\windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//中文宋体
                BaseFont bfHei = BaseFont.createFont(@"c:\windows\Fonts\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//黑体


bitmap = new Bitmap(width, height);
                        graphics = Graphics.FromImage(bitmap);
                        graphics.DrawString("哈喽哈喽哈喽", bfHei,
                            Brushes.Black, new PointF(stringX, stringY));
                        graphics.Flush();
                        bitmap.Save(dir + i.ToString() + ".png",
                            System.Drawing.Imaging.ImageFormat.Png);
                        graphics.Dispose();
                        bitmap.Dispose();
  相关解决方案