如何繪製平滑的反走樣線
阿新 • • 發佈:2019-01-04
在Windows程式設計的時候,我們經常可以發現我們自己在程式中畫的線條都不直,在畫斜線的時候會出現很多的鋸齒,那麼如何繪製非常平滑的線條呢,答案就是使用反走樣技術,具體到Windows平臺,我們可以直接使用GDI+提供的函式來直接實現,下面是一個簡單的實現步驟:
1、加入標頭檔案
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
2、在.h檔案中宣告GDI+
ULONG_PTR m_gdiplusToken;
GdiplusStartupInput m_gdiplusStartupInput;
3、在.cpp檔案中設定線為高質量平滑模式
using namespace Gdiplus;
Graphics graphics(hdc);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
4、呼叫新的GDI+函式
Pen newPen(線的顏色, 線的大小);
graphics.DrawLine(&newPen, x1, y1, x2, y2);