Ellipse函数画圆

Ellipse函数的用法  

函数功能:该函数用于画一个椭圆,椭圆的中心是限定矩形的中心,使用当前画笔画椭圆,用当前的画刷填充椭圆。

    函数原型:BOOL Ellipse(HDC hdc, int nLeftRect, int nTopRect, nRightRect, int nBottomRect);

    参数:

    hdc:设备环境句柄。

    nLeftRect:指定限定矩形左上角的X坐标。

    nTopRect:指定限定矩形左上角的Y坐标。

    nRightRect:指定限定矩形右下角的X坐标。

    nBottomRect:指定限定矩形右下角的Y坐标。

    返回值:如果函数调用成功,返回值非零;如果函数调用失败,返回值是0。

    Windows NT:若想获得更多错误信息,请调用GetLastError函数。

    备注:椭圆既不使用也不改变当前位置。

    Windows 95和Windows 98:限定矩形的坐标值之和不能超过32767。nLeftRect与nRigthRect或nTopRectn与BottomRect之和不能超过32767

 

Ellipse(x1,y1,x2,y2),你必须确保x2-x1==y2-y1,这样你画出的就是正圆,而不是椭圆了.

不用Windows自带的画椭圆函数画椭圆方法参考

/
// Draw a ellipse mid point algorthism
/
void CGraphicsView::midleEllipse(int xCenter, int yCenter, int Rx, int Ry, HDC dc)
{
int Rx2 = Rx*Rx;
int Ry2 = Ry*Ry;
int twoRx2 = 2*Rx2;
int twoRy2 = 2*Ry2;
int p;
int x=0;
int y=Ry;
int px = 0;
int py = twoRx2*y;
SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
//Region 1
p = (int)(Ry2-Rx2*Ry+0.25*Rx2);
while(px<py)
{
x++;
px+=twoRy2;
if(p<0)
p+=Ry2+px;
else
{
y--;
py-=twoRx2;
p+=Ry2+px-py;
}
SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
}
//Region 2
p = (int)(Ry2*(x+0.5)*(x+0.5)+Rx2*(y-1)*(y-1)-Rx2*Ry2);
while(y>0)
{
y--;
py-=twoRx2;
if(p>0)
p+=Rx2-py;
else
{
x++;
px+=twoRy2;
p+=Rx2-py+px;
}
SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));
}

}

/
// Draw a circle
/
void circleMidpoint(int xCenter,int yCenter,int radius,HDC dc)
{
int x = 0;
int y = radius;
int p=1-radius;
while(x<y)
{
x++;
if(p<0)
{
p+=2*x+1;
}
else
{
y--;
p+=2*(x-y)+1;
}
SetPixel(dc,xCenter+x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter+y,RGB(255,0,0));
SetPixel(dc,xCenter+x,yCenter-y,RGB(255,0,0));
SetPixel(dc,xCenter-x,yCenter-y,RGB(255,0,0));

SetPixel(dc,xCenter+y,yCenter+x,RGB(255,0,0));
SetPixel(dc,xCenter-y,yCenter+x,RGB(255,0,0));
SetPixel(dc,xCenter+y,yCenter-x,RGB(255,0,0));
SetPixel(dc,xCenter-y,yCenter-x,RGB(255,0,0));
}
}

 

  • 5
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值