【发布时间】:2012-03-02 23:01:22
【问题描述】:
在以下代码中,我尝试绘制两条线:一条具有子像素宽度 (0.5),另一条具有 1px 宽度:
var img = new Bitmap(256, 256);
Graphics graphics = Graphics.FromImage(img);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
// Draw a subpixel line (0.5 width)
graphics.DrawLine(new Pen(Color.Red, (float)0.5), 0, 100, 255, 110);
// Draw a single pixel line (1 width)
graphics.DrawLine(new Pen(Color.Red, (float)1), 0, 110, 255, 120);
img.Save(@"c:\temp\test.png", ImageFormat.Png);
graphics.Dispose();
img.Dispose();
但是,在生成的图像中,两条线的宽度相同:
有没有办法让顶线出现亚像素(0.5px)?
【问题讨论】:
-
请不要在标题前加上“C#”之类的前缀。这就是标签的用途。
-
假设您的目标是有意义的。推断一下,您希望笔宽为 0.001 像素的线条看起来如何?
-
如果您使用图形应用程序缩小具有 1 像素线的图像,生成的图像将显示暗线。
标签: c# .net graphics system.drawing