绘制折线会产生像素化线 [英] Drawing Polyline results in pixelated line

查看:69
本文介绍了绘制折线会产生像素化线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自己的本机win32 C ++复选框,该复选框可以具有透明背景.这样做的目的是使窗口/小部件看起来与Windows XP样式复选框完全一样,只是它可以具有透明的背景.

I am trying to create my own Native win32 C++ Checkbox that can have a transparent background. The idea is to make the window/widget look exactly like the Windows XP style checkbox except that it can have a transparent background.

我的问题:当我为文本框绘制刻度线时,刻度线"看起来像是像素化和锯齿状的-请看下面的图片.它看起来不像实际的复选框打勾.

My Problem: When I draw the tick for my textbox, the 'tick' line looks pixelated and jagged - see my picture below for how it looks. It does not look smooth like the actual checkbox tick.

左边的复选框是我的,右边的是我尝试复制的默认窗口:

The left checkbox is mine, the right is the default windows one I am trying to replicate:

如何使刻度线平滑且没有像素化.我可以使用Win32 GDI函数绘制刻度线.我应该使用位图图像而不是在GDI中绘制刻度线吗?目前,我使用PolylineTo()绘制刻度线.也许我应该使用PolylineToEx()?

How can I make my tick smooth and not pixelated. What is a Win32 GDI function I could use to draw the tick. Should I use a bitmap image instead of drawing the tick in GDI? Currently I use PolylineTo() to draw the tick. Maybe I should use PolylineToEx()?

任何建议将不胜感激.

用于绘制刻度线的代码(此代码在WM_PAINT中):

Code for drawing the tick(this code is in WM_PAINT):

 HGDIOBJ hPen      = CreatePen(PS_SOLID, 2, RGB(45,45,45)); //ExtCreatePen(PS_COSMETIC, dwPenStyle[i], 1, &lb, 0, NULL); 
 HGDIOBJ hPenOld   = SelectObject(hdc, hPen); 
 POINT tickPnts[3] = {{3,((height-CHECK_RECTH)/2)+6}, {5,((height-CHECK_RECTH)/2)+9}, {9,((height-CHECK_RECTH)/2)+2}};
 MoveToEx(hdc, tickPnts[0].x, tickPnts[0].y, NULL);
 PolylineTo(hdc, tickPnts, 3);
 SelectObject(hdc, hPenOld); 
 DeleteObject(hPen); 

推荐答案

Windows使用 Marlett 字体以呈现复选框刻度,窗口框架按钮和其他可缩放的UI元素.您可以使用抗锯齿渲染字体以获得平滑的边缘.

Windows uses the Marlett font to render checkbox ticks, the window frame buttons and other scalable UI elements. You can render the font with anti-aliasing to get smooth edges.

(这肯定曾经是正确的;我不确定Windows 7中的新窗口框架按钮是否使用该字体,但是该字体仍然存在.)

(This certainly used to be true anyway; I don't know for sure that the new window frame buttons in Windows 7 use the font, but the font still exists.)

GDI不进行任何抗锯齿处理,这就是您的线条看上去锯齿状的原因.

GDI doesn't do any anti-aliasing, which is why your lines look jagged.

这篇关于绘制折线会产生像素化线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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