兄弟对图形处理方面没有什么研究。手头有一项目比较急,其中需要画一些直线,用LineTo试了一下,直线有锯齿,不太美观。求各位大哥给一个反走样算法,有源码更好,谢谢了!
解决方案 »
- 如何用SendDlgItemMessage 修改控件属性
- 在VC中向SQL Sever数据库插入数据
- VC的DLL如何在C#中使用?
- 用socket编程实现一个简单的网络文件传输程序,如何把客户端和服务器端合为一体,即要求只启动一个程序就既能接收文件又能发送文件?
- 在vc中如何在一个工作区调试2个exe工程?
- 多谢ndy_w(carpe diem)大侠帮我解决问题“请问以下代码在VC中为何编译不过?? ”送二百分!
- 怎样在对话框的任意位置显示图标?
- 为啥俺的classwizard出不来哦?
- 怎样执行Script语句(VC)
- 数据库中的odbc和dao技术那种现在比较流行!
- VC下操作Oracle数据库问题.急
- 如何从一个treectrl中拖拽一个节点到toolbar中?
http://www.codeguru.com/gdi/GDIPlus.html
当然,msdn上资料更多,在http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/cpp_gdi+start_26ic.asp
慢慢看吧,不过我觉得仍感不够过,所以最好的办法是边看边实践
如果你觉得有用,给我加分吧
// anti-aliased line
void CMapView::WuLine(CDC* pDC, CPoint& pt1, CPoint& pt2, int color)
{
int deltax, deltay, start, finish;
double dx, dy, dydx; // fractional parts
BYTE LR, LG, LB;
int x1, x2, y1, y2;
double d1, d2;
x1 = pt1.x; y1 = pt1.y;
x2 = pt2.x; y2 = pt2.y;
deltax = abs(x2 - x1); // Calculate deltax and deltay for initialisation
deltay = abs(y2 - y1);
if((deltax == 0)||(deltay == 0))
{
pDC->MoveTo(x1, y1);
pDC->LineTo(x2, y2);
return;
}
LR = color & 0x0000FF;
LG = (color & 0x00FF00) >> 8;
LB = (color & 0xFF0000) >> 16;
if(deltax > deltay) // then begin // horizontal or vertical
{
if(y2 > y1) // determine rise and run
dydx = -((double)deltay / deltax);
else
dydx = (double)deltay / deltax;
if(x2 < x1)
{
start = x2; // right to left
finish = x1;
dy = y2;
}
else
{
start = x1; // left to right
finish = x2;
dy = y1;
dydx = -dydx; // inverse slope
}
for (int x = start; x <= finish; x++)
{
d2 = modf(dy, &d1); AlphaBlendPixel(pDC, x, (int)d1, LR, LG, LB, 1 - d2);
AlphaBlendPixel(pDC, x, (int)d1 + 1, LR, LG, LB, d2);
dy = dy + dydx; // next point
}
}
else
{
if(x2 > x1) // determine rise and run
dydx = -((double)deltax / deltay);
else
dydx = (double)deltax / deltay;
if(y2 < y1)
{
start = y2; // right to left
finish = y1;
dx = x2;
}
else
{
start = y1; // left to right
finish = y2;
dx = x1;
dydx = -dydx; // inverse slope
} for(int y = start; y <= finish; y++)
{
d2 = modf(dx, &d1); AlphaBlendPixel(pDC, (int)d1, y, LR, LG, LB, 1 - d2);
AlphaBlendPixel(pDC, (int)d1 + 1, y, LR, LG, LB, d2);
dx = dx + dydx;
}
}
}// blend a pixel with the current colour and a specified colour
void CMapView::AlphaBlendPixel(CDC* pDC, int x, int y, BYTE R, BYTE G, BYTE B, double ratio)
{
double minus_ratio;
int color_old;
BYTE R1, G1, B1;
BYTE R2, G2, B2;
if((x < 0) || (x >= m_iWidth) || (y < 0) || (y >= m_iHeight))
return;
color_old = pDC->GetPixel(x, y);
R1 = color_old & 0x0000FF;
G1 = (color_old & 0x00FF00) >> 8;
B1 = (color_old & 0xFF0000) >> 16;
minus_ratio = 1 - ratio;
B2 = (int)(B*ratio + B1*minus_ratio);
G2 = (int)(G*ratio + G1*minus_ratio);
R2 = (int)(R*ratio + R1*minus_ratio);
pDC->SetPixel(x, y, RGB(R2, G2, B2));
}