gpt4 book ai didi

c# - 如何绘制亚像素线

转载 作者:可可西里 更新时间:2023-11-01 08:26:30 29 4
gpt4 key购买 nike

在下面的代码中,我尝试绘制两条线:一条线的宽度为亚像素 (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();

但是,在生成的图像中,两条线的宽度相同:

enter image description here

有没有办法让顶线出现子像素(0.5px)?

编辑经过一些研究,AGG可能是要走的路,其中有一个 c# port .

最佳答案

你可以通过绘制 x2 然后缩小它来破解它:

        Image img2x = new Bitmap(256*2, 256*2);
Graphics g2x = Graphics.FromImage(img2x);
g2x.SmoothingMode = SmoothingMode.AntiAlias;
g2x.DrawLine(new Pen(Color.Red, 0.5f*2), 0, 100*2, 255*2, 110*2);

Image img = new Bitmap(256, 256);
Graphics g = Graphics.FromImage(img);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(img2x, 0, 0, 256, 256);

g.DrawLine(new Pen(Color.Red, 1f), 0, 110, 255, 120);

img.Save(@"c:\tmep\test.png", ImageFormat.Png);

enter image description here

关于c# - 如何绘制亚像素线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9541575/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com