如何画一个子像素线 [英] How to draw a subpixel line

查看:173
本文介绍了如何画一个子像素线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下code,我想画两条线:一是与一个子像素宽度(0.5)和其他与1px的宽度:

In the following code, I'm trying to draw two lines: One with a subpixel width (0.5) and the other with 1px width:

        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();

但是,生成的图像中,这两条线会出现相同的宽度:

However, in the generated image, both lines appear the same width:

有没有办法在第一行显示的子像素(0.5px)

Is there a way for the top line to appear sub-pixel (0.5px)?

编辑:经过一番研究, AGG 可能是要走的路,其中有一个 C#端口

After some research, AGG might be the way to go, of which there is a c# port.

推荐答案

根据该的的文档

width属性被设置为在宽度参数指定的值。的宽度为0,将导致钢笔画,仿佛宽度分别为1。

The Width property is set to the value specified in the width parameter. A width of 0 will result in the Pen drawing as if the width were 1.

有可能是一个适用于任何宽度小于一,而不仅仅是宽度是precisely等于0

It may be that that applies to any width less than one, not just widths that are precisely equal to 0.

这篇关于如何画一个子像素线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆