整理日: 2015年2月16日

这几天一直在研究win32 SDk下画线去锯齿,之前一直用的QT的画线接口函数,里面有去锯齿的效果,可是突然项目要求不能用QT的只能用win32 SDK下的GDI画线接口函数,可是显示的效果有锯齿,怎么办?只能研究下怎么去锯齿影响,因为GDI下没有去锯齿的处理,所以只能自己找算法处理。

在网上找了一下

http://www.codeproject.com/KB/GDI/CTGraphics.aspx

http://www.codeproject.com/KB/GDI/AntiAliasing.aspx

http://www.codeproject.com/KB/GDI-plus/AntiAliasingIssues.aspx

反走样技术之一 Wu像素

http://dev.gameres.com/Program/Visual/3D/Antialiasing.htm

http://dev.gameres.com/Program/Visual/Effects/WuLine.htm

什么是防锯齿技术?什么是亚像素? - Apple4.us

可是这些方法的画线处理不能设置线宽,我的画线处理需要线宽,按照网上找到的去锯齿的代码,我改了下代码(见后),修改的代码并不能灵活设置的线宽,两个端点处理也需要完善,最主要的是我不知道怎么去处理两个端点。搞了好几天,还是没有找到端点处理的合适方式。

void RVS_drawLine_width(HDC hDC, int x1, int y1, int x2, int y2, COLORREF color)
{
// Calculate line params
int dx = (x2 - x1);
int dy = (y2 - y1);
COLORREF bgColor;
int temp;
float k; // X-dominant line
if (abs(dx) > abs(dy))
{
// Ex-change line end points
if (dx < 0)
{
temp = x1;
x1 = x2;
x2 = temp; temp = y1;
y1 = y2;
y2 = temp;
}
k = (float)dy / (float)dx; int xs;
float yt = (float)y1;
float distance;
UCHAR red, green, blue; for (xs = x1; xs <= x2; xs++)
{
distance = (float)(yt - (int)(yt)); bgColor = ::GetPixel(hDC, xs, (int)yt - 1);
red = (UCHAR)(distance * GetRValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetRValue(color));
green = (UCHAR)(distance * GetGValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetGValue(color));
blue = (UCHAR)(distance * GetBValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetBValue(color));
::SetPixel(hDC, xs, (int)yt - 1, RGB(red, green, blue)); // ::SetPixel(hDC, xs, (int)yt-1, color);
::SetPixel(hDC, xs, (int)yt, color); bgColor = ::GetPixel(hDC, xs, (int)yt + 1);
red = (UCHAR)((1.0f - distance) * GetRValue(bgColor)) +
(UCHAR)(distance * GetRValue(color));
green = (UCHAR)((1.0f - distance) * GetGValue(bgColor)) +
(UCHAR)(distance * GetGValue(color));
blue = (UCHAR)((1.0f - distance) * GetBValue(bgColor)) +
(UCHAR)(distance * GetBValue(color));
::SetPixel(hDC, xs, (int)yt + 1, RGB(red, green, blue)); yt += k;
} }
// Y-dominant line
else
{
// Ex-change line end points
if (dy < 0)
{
temp = x1;
x1 = x2;
x2 = temp; temp = y1;
y1 = y2;
y2 = temp;
}
k = (float)dx / (float)dy; int ys;
float xt = (float)x1;
float distance;
UCHAR red, green, blue;
for (ys = y1; ys <= y2; ys++)
{
distance = (float)(xt - (int)(xt)); bgColor = ::GetPixel(hDC, (int)xt - 1, ys);
red = (UCHAR)(distance * GetRValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetRValue(color));
green = (UCHAR)(distance * GetGValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetGValue(color));
blue = (UCHAR)(distance * GetBValue(bgColor)) +
(UCHAR)((1.0f - distance) * GetBValue(color));
::SetPixel(hDC, (int)xt - 1, ys, RGB(red, green, blue)); // ::SetPixel(hDC, (int)xt-1, ys, color);
::SetPixel(hDC, (int)xt, ys, color); bgColor = ::GetPixel(hDC, (int)xt + 1, ys);
red = (UCHAR)((1.0f - distance) * GetRValue(bgColor)) +
(UCHAR)(distance * GetRValue(color));
green = (UCHAR)((1.0f - distance) * GetGValue(bgColor)) +
(UCHAR)(distance * GetGValue(color));
blue = (UCHAR)((1.0f - distance) * GetBValue(bgColor)) +
(UCHAR)(distance * GetBValue(color));
::SetPixel(hDC, (int)xt + 1, ys, RGB(red, green, blue)); xt += k;
}
} }

win32画线考虑去锯齿的更多相关文章

  1. PHP合成图片、生成文字、居中对齐、画线、矩形、三角形、多边形、图片抗锯齿、不失真 高性能源码示例

    function generateImg($source, $text1, $text2, $text3, $font = './msyhbd.ttf') { $date = '' . date ( ...

  2. CGContextRef 画线简单用法

    CGContextRef CGContextMoveToPoint(context,150,50);//圆弧的起始点 CGContextAddArcToPoint(context,100,80,130 ...

  3. C#使用 DirectX SDK 9做视频播放器 并在视频画线添加文字 VMR9

    视频图像处理系列 索引 VS2013下测试通过. 在百度中搜索关键字“DirectX SDk”,或者进入微软官网https://www.microsoft.com/en-us/download/det ...

  4. unity3d 使用GL 方式画线

    这个是画线部分 private Vector3[] linePoints; public int m_LineCount; public int m_PointUsed; public void Re ...

  5. Delphi下OpenGL2d绘图(03)-画线

    一.前言 画线与画点基本上代码是相同.区别在于glBegin()的参数.绘制的框架代码可以使用 Delphi下OpenGL2d绘图(01)-初始化 中的代码.修改的部份为 Draw 函数的内容. 二. ...

  6. android 屏幕上面画线

    作业如下:在android屏幕上面任意画线 package feng.f121.drawline;//本人创建的包名,每人有每人的不同的包 import java.security.PublicKey ...

  7. unity3d NavMeshAgent 寻路画线/画路径

    今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...

  8. openGL线型和线宽以及线的抗锯齿

    openGL线型和线宽以及线抗锯齿 一. 线宽 Opengl的线宽设置:glLineWidth(width); width为float类型值,在0~10.0,大于10以上按10来处理. 若开启线的反走 ...

  9. 用OpenGL画线

    . 两点之间的连线称之为线段,在屏幕上显示线段放在现在已经不是稀奇的事情,大多数高级图形API都可以轻松实现,我尝试用OpenGL画线,在这里记录一下收获. . OpenGL这个级别的图形API,通常 ...

随机推荐

  1. C# 动态创建出来的窗体间的通讯 delegate3

    附件1:http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate03.rar 一个RTF文件管理器 描述 Form2,Form3,For ...

  2. resin 4.0数据源的配置

    在resin 的conf 文件下有resin.xml  我们在这里能够配置数据源以及配置项目 一.配置多个数据源,多个项目共享这些数据源.也就是这些数据源配置在<host>   </ ...

  3. [Eclipse]The type XXX cannot be resolved. It is indirectly referenced from required .class files

    在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...

  4. sybase SA密码重置

    sa 密码忘记解决之道: su - sybase cd ASE/install vi RUN_etoh2 在文件的末尾加入 -psa \ 停止原数据库服务 由于密码遗忘,所以只能通过kill进程停止服 ...

  5. Oracle中not exists 与not in 的使用情况

    1.在oracle11g以上版本,oracle已经做了优化,能够自动将in优化成exists方式,因此oracle11g以上版本,使用in和exists效果是一样的. 2.在oracle中,使用not ...

  6. GitHub安装失败

    安装GitHub客户端的时候,会提示失败,如下: An error occurred trying to download 'http://github-windows.s3.amazonaws.co ...

  7. Spring Framework jar官方直接下载路径

    SPRING官方网站改版后,建议都是通过 Maven和Gradle下载,对不使用Maven和Gradle开发项目的,下载就非常麻烦,下给出Spring Framework jar官方直接下载路径: h ...

  8. c语言训练题:关于张三李四王五说谎的问题(此处用javascript实现)

    (第一篇博文) 今天在一个交流群里见他们无聊,然后找到之前收藏的一些c语言题目放出去想让他们做,结果反倒是自己不会做,于是花了很多时间去想. 原题:张三说李四在说谎,李四说王五在说谎,王五说张三和李四 ...

  9. [访问系统] C#计算机信息类ComputerInfo (转载)

    下载整个包,只下载现有类是不起作用的 http://www.sufeinet.com/thread-303-1-1.html 点击此处下载 using System; using System.Man ...

  10. SQL大量数据查询的优化 及 非用like不可时的处理方案

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...