用画点的函数SetPixel实现画线的功能
来源:互联网 发布:纪录片知乎 编辑:程序博客网 时间:2024/06/06 00:39
void CDlgMain::UpdateDraw(CDC* pDC, CRect rect)
{
//如果位图不够大,则重新申请
if( m_bitmap.m_hObject )
{
BITMAP info;
m_bitmap.GetBitmap( &info );
//释放原来的小位图
if( info.bmWidth<rect.Width() || info.bmHeight<rect.Height() )
m_bitmap.DeleteObject();
}
// pDC->FillRect(rect, &CBrush(RGB(0, 255, 0)));
// int i, j;
// double a, b;
// a = 5;
//
// for (i=0; i<50; i++)
// {
// b = (int)sqrt(a);
// j = b * i;
//
// pDC->SetPixel(i, j, RGB(255, 0, 0));
// }
MoveDraw(100, 50, 300, 1);
// pDC->MoveTo(100, 50);
// pDC->LineTo(300, 1);
pDC->BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), pDC, rect.left, rect.top, SRCCOPY );
}
BOOL CDlgMain::OnEraseBkgnd(CDC* pDC)
{
// CRect rc;
// GetClientRect(rc);
// pDC->FillRect(rc, &CBrush(RGB(0, 0, 255)));
return CDialog::OnEraseBkgnd(pDC);
}
void CDlgMain::MoveDraw(int x1, int y1, int x2, int y2)
{
CDC* pDC = GetDC();
int i, j;
double x, y, tanValue;
//求绝对值:int abs(int x);
x = abs(int (x2-x1));
y = abs(int (y2-y1));
/*****************************************/
//1. x1<x2; y1<y2;
//2. x1>x2; y1<y2;
//3. x1<x2; y1>y2;
//4. x1>x2; y1>y2;
//5. x1=x2; y1<y2;
//6. x1=x2; y1>y2;
//7. x1<x2; y1=y2;
//8. x1>x2; y1=y2;
//
/*****************************************/
// /*1. x1<x2; y1<y2;************************/
if (x1<x2 && y1<y2)
{
for (i=0; i<x; i++)
{
//tan(角度) tanValue = y/x; y = tanValue * x;
//cot(角度) cotValue = x/y; x = cotValue * y;
tanValue = y/x;
x2 = i + x1;
y2 = i*tanValue + y1;
//pDC->SetPixel(i , i*cot(X), RGB(255, 0, 0));
//pDC->SetPixel(x, x*cotValue, RGB(255, 0, 0));
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*2. x1>x2; y1<y2;*****************************/
else if (x1>x2 && y1<y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 - i;
y2 = y1 + i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*3. x1<x2; y1>y2;*************************/
else if (x1<x2 && y1>y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 + i;
y2 = y1 - i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*4. x1>x2; y1>y2;*************************/
else if (x1>x2 && y1>y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 - i;
y2 = y1 - i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*5 x1<x2; y1=y2;**********************************/
else if (x1<x2 && y1==y2)
{
for (i=0; i<x; i++)
{
//3. x1<x2; y1=y2;
x2 = x1 + i;
y2 = y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*6. x1>x2; y1=y2;***********************************/
else if ( x1>x2 && y1==y2)
{
for (i=0; i<x; i++)
{
//4. x1>x2; y1=y2;
x2 = x1 - i;
y2 = y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*7. x1=x2; y1<y2;****************************************/
else if (x1==x2 && y1<y2)
{
for (i=0; i<y; i++)
{
//1. x1=x2; y1<y2;
x2 = x1;
y2 = i + y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*8. x1=x2; y1>y2;***********************************/
else if (x1==x2 && y1>y2)
{
for (i=0; i<y; i++)
{
//2. x1=x2; y1>y2;
x2 = x1;
y2 = y1 - i;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
}
{
//如果位图不够大,则重新申请
if( m_bitmap.m_hObject )
{
BITMAP info;
m_bitmap.GetBitmap( &info );
//释放原来的小位图
if( info.bmWidth<rect.Width() || info.bmHeight<rect.Height() )
m_bitmap.DeleteObject();
}
// pDC->FillRect(rect, &CBrush(RGB(0, 255, 0)));
// int i, j;
// double a, b;
// a = 5;
//
// for (i=0; i<50; i++)
// {
// b = (int)sqrt(a);
// j = b * i;
//
// pDC->SetPixel(i, j, RGB(255, 0, 0));
// }
MoveDraw(100, 50, 300, 1);
// pDC->MoveTo(100, 50);
// pDC->LineTo(300, 1);
pDC->BitBlt( rect.left, rect.top, rect.Width(), rect.Height(), pDC, rect.left, rect.top, SRCCOPY );
}
BOOL CDlgMain::OnEraseBkgnd(CDC* pDC)
{
// CRect rc;
// GetClientRect(rc);
// pDC->FillRect(rc, &CBrush(RGB(0, 0, 255)));
return CDialog::OnEraseBkgnd(pDC);
}
void CDlgMain::MoveDraw(int x1, int y1, int x2, int y2)
{
CDC* pDC = GetDC();
int i, j;
double x, y, tanValue;
//求绝对值:int abs(int x);
x = abs(int (x2-x1));
y = abs(int (y2-y1));
/*****************************************/
//1. x1<x2; y1<y2;
//2. x1>x2; y1<y2;
//3. x1<x2; y1>y2;
//4. x1>x2; y1>y2;
//5. x1=x2; y1<y2;
//6. x1=x2; y1>y2;
//7. x1<x2; y1=y2;
//8. x1>x2; y1=y2;
//
/*****************************************/
// /*1. x1<x2; y1<y2;************************/
if (x1<x2 && y1<y2)
{
for (i=0; i<x; i++)
{
//tan(角度) tanValue = y/x; y = tanValue * x;
//cot(角度) cotValue = x/y; x = cotValue * y;
tanValue = y/x;
x2 = i + x1;
y2 = i*tanValue + y1;
//pDC->SetPixel(i , i*cot(X), RGB(255, 0, 0));
//pDC->SetPixel(x, x*cotValue, RGB(255, 0, 0));
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*2. x1>x2; y1<y2;*****************************/
else if (x1>x2 && y1<y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 - i;
y2 = y1 + i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*3. x1<x2; y1>y2;*************************/
else if (x1<x2 && y1>y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 + i;
y2 = y1 - i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*4. x1>x2; y1>y2;*************************/
else if (x1>x2 && y1>y2)
{
for (i=0; i<x; i++)
{
tanValue = y/x;
x2 = x1 - i;
y2 = y1 - i*tanValue;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*5 x1<x2; y1=y2;**********************************/
else if (x1<x2 && y1==y2)
{
for (i=0; i<x; i++)
{
//3. x1<x2; y1=y2;
x2 = x1 + i;
y2 = y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*6. x1>x2; y1=y2;***********************************/
else if ( x1>x2 && y1==y2)
{
for (i=0; i<x; i++)
{
//4. x1>x2; y1=y2;
x2 = x1 - i;
y2 = y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*7. x1=x2; y1<y2;****************************************/
else if (x1==x2 && y1<y2)
{
for (i=0; i<y; i++)
{
//1. x1=x2; y1<y2;
x2 = x1;
y2 = i + y1;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
/*8. x1=x2; y1>y2;***********************************/
else if (x1==x2 && y1>y2)
{
for (i=0; i<y; i++)
{
//2. x1=x2; y1>y2;
x2 = x1;
y2 = y1 - i;
pDC->SetPixel(x2, y2, RGB(255, 0, 0));
}
}
}
0 0
- 用画点的函数SetPixel实现画线的功能
- iOS-实现最简单的画线功能
- IOS简单的画线功能实现
- 画线算法的实现
- 利用MFC的CClientDC类实现画线功能
- 启用MFC的CClientDC类实现画线功能
- 利用MFC 的CDC 类实现画线功能
- iOS-实现最简单的画线功能 . 转
- Python 使用 pylab 库实现画线功能的方法详解
- 最简单的画线功能
- 最简单的画线功能
- 最简单的画线功能
- 小字典之MFC简单的多线程调用类的成员函数实现逐步画线功能 VS2015 C++ 完成
- [iOS]画线功能实现
- 利用SDK全局函数实现画线功能详解
- 随机画出随机颜色的点 SetPixel
- setpixel,getpixel效率太低的问题
- 利用SDK与MFC实现画线功能的五种方法
- [C#] 控制系统音量-第一章
- HTTP协议详解
- “校园的雨 ”——落花,散了一地
- 请点击这个链接阅读详细介绍:http://g.csdn.net/5265982
- ant执行编译 警告:编码 GBK 的不可映射字符(搜集整理)
- 用画点的函数SetPixel实现画线的功能
- VirtualBox 开机自动挂载共享文件夹
- 定时器队列
- 瑞典专家用死老鼠将一只蟒蛇从扬声器中引出
- POJ 3233 Matrix Power Series (矩阵 + 二分)
- hdu3491最小割转最大流+拆点
- 直方图均衡化(色调均化)(一)
- PB 数据窗口分页显示
- 如果利用新教室网攻克听力难关?