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

fordawn 2015-05-15 05:10:35
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();


为啥会出现加粗效果啊,怎么能显示出正常的字呢?
...全文
765 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
fordawn 2015-05-19
  • 打赏
  • 举报
回复
引用 10 楼 yangb0803 的回复:
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);
这样就不透明啦
fordawn 2015-05-19
  • 打赏
  • 举报
回复
引用 11 楼 zyl_leilei 的回复:

//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();
多谢。
fordawn 2015-05-19
  • 打赏
  • 举报
回复
引用 9 楼 wawd74520 的回复:
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; 这个调整下。
这个有效,改成AntiAlias显示的效果会更好一些。
-小蕾- 2015-05-19
  • 打赏
  • 举报
回复

//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();
道玄希言 2015-05-19
  • 打赏
  • 举报
回复
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);
失落的神庙 2015-05-19
  • 打赏
  • 举报
回复
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; 这个调整下。
失落的神庙 2015-05-19
  • 打赏
  • 举报
回复
new Font("微软雅黑", 20, FontStyle.Regular)
fordawn 2015-05-18
  • 打赏
  • 举报
回复
引用 4 楼 caozhy 的回复:
Graphics.SmoothingMode设置下
https://msdn.microsoft.com/zh-cn/library/system.drawing.graphics.smoothingmode.aspx


Bitmap bitmap = new Bitmap(750, 35);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawString("哈喽哈喽哈喽", new Font("微软雅黑", 20),
Brushes.Black, new PointF(0, 0));
graphics.Flush();
bitmap.Save("test.png",
System.Drawing.Imaging.ImageFormat.Png);
graphics.Dispose();
bitmap.Dispose();


可能你们没明白我的意思,我上个对比图你们看一下
fordawn 2015-05-18
  • 打赏
  • 举报
回复
引用 2 楼 wawd74520 的回复:
你系统里有微软雅黑么?
什么字体这显示也不正常吧?有微软雅黑
fordawn 2015-05-18
  • 打赏
  • 举报
回复
引用 1 楼 wyd1520 的回复:
微软雅黑 就是这么粗吧。
你改用宋体就不一样了。




Bitmap bitmap = new Bitmap(750, 35);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawString("哈喽哈喽哈喽", new Font("宋体", 20),
Brushes.Black, new PointF(0, 0));
graphics.Flush();
bitmap.Save("test.png",
System.Drawing.Imaging.ImageFormat.Png);
graphics.Dispose();
bitmap.Dispose();
threenewbee 2015-05-15
  • 打赏
  • 举报
回复
Graphics.SmoothingMode设置下 https://msdn.microsoft.com/zh-cn/library/system.drawing.graphics.smoothingmode.aspx
无涯大者 2015-05-15
  • 打赏
  • 举报
回复
微软雅黑必须要下载到系统字体里面,才可以显示出来!
失落的神庙 2015-05-15
  • 打赏
  • 举报
回复
你系统里有微软雅黑么?
本拉灯 2015-05-15
  • 打赏
  • 举报
回复
微软雅黑 就是这么粗吧。 你改用宋体就不一样了。

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧