windows程序设计第五版_windows程序设计入门

windows程序设计第五版_windows程序设计入门Ellipse函数的用法函数功能:该函数用于画一个椭圆,椭圆的中心是限定矩形的中心,使用当前画笔画椭圆,用当前的画刷填充椭圆。函数原型:BOOL Ellipse(HDC hdc, int nLeftRect, int nTopRect, nRightRect, int nBottomRect);参数:hdc:设备环境句柄。nLeftRect:指定限定矩形左上角的X坐标。nTopRect…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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自带的画椭圆函数画椭圆方法参考

代码如下:


//画一个椭圆中点算法
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));
	}

}


// 画圆
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));
	}
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170964.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号