图形裁剪代码.docx

上传人:b****3 文档编号:2791379 上传时间:2022-11-15 格式:DOCX 页数:14 大小:16.49KB
下载 相关 举报
图形裁剪代码.docx_第1页
第1页 / 共14页
图形裁剪代码.docx_第2页
第2页 / 共14页
图形裁剪代码.docx_第3页
第3页 / 共14页
图形裁剪代码.docx_第4页
第4页 / 共14页
图形裁剪代码.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

图形裁剪代码.docx

《图形裁剪代码.docx》由会员分享,可在线阅读,更多相关《图形裁剪代码.docx(14页珍藏版)》请在冰豆网上搜索。

图形裁剪代码.docx

图形裁剪代码

ͼÐβüô´úÂë.txt7ÎÂůÊÇƮƮÈ÷È÷µÄ´ºÓꣻÎÂůÊÇдÔÚÁ³ÉϵÄЦӰ£»ÎÂůÊÇÒåÎÞ·´¹ËµÄÏìÓ¦£»ÎÂůÊÇһ˿²»¹¶µÄÅäºÏ¡£8×ðÖØÊÇÒ»ÂÆ´º·ç£¬Ò»ãüÇåȪ£¬Ò»¿Å¸øÈËÎÂůµÄÊæÐÄÍ裬һ¼Á´ßÈ˷ܽøµÄÇ¿ÐļÁCPointptset[N],pt[N],pts[N],ptse[N],p[N],ptset1[N];

 

#defineLEFT1

#defineRIGHT2

#defineBOTTOM4

#defineTOP8

#defineXL100

#defineXR300

#defineYT100

#defineYB250

 

CPennewpen(PS_SOLID,1,RGB(255,0,0));

CPen*old=pDC->SelectObject(&newpen);

pDC->Rectangle(CRect(XL,YT,XR,YB));//¼ôÇд°¿Ú

ptset[0]=CPoint(120,150);

ptset[1]=CPoint(170,110);

ptset[2]=CPoint(0,190);

ptset[3]=CPoint(350,150);

ptset[4]=CPoint(0,250);

ptset[5]=CPoint(150,230);

ptset[6]=CPoint(200,50);

ptset[7]=CPoint(120,150);

ptset1[0]=CPoint(20,150);

ptset1[1]=CPoint(170,110);

ptset1[2]=CPoint(250,150);

ptset1[3]=CPoint(200,230);

ptset1[4]=CPoint(20,150);

pDC->TextOut(0,20,"Ë«»÷Êó±ê×ó¼ü£¬³öÏÖÒª¼ôÇеÄÏ߶Î");

pDC->TextOut(0,50,"Ë«»÷Êó±êÓÒ¼ü£¬³öÏÖÒª¼ôÇеĶà±ßÐÎ");

pDC->SelectObject(old);

}

 

CDC*pDC=GetDC();

CPennewpen(PS_SOLID,1,RGB(255,0,0));

CPen*old=pDC->SelectObject(&newpen);

for(inti=0;i

{

pDC->MoveTo(ptset[i]);

pDC->LineTo(ptset[i+1]);

i++;

}

CView:

:

OnLButtonDblClk(nFlags,point);

}

 

CDC*pDC=GetDC();

CPennewpen(PS_SOLID,1,RGB(0,255,0));

CPen*old=pDC->SelectObject(&newpen);

floatx,y;

inti;

intcode1,code2;

RedrawWindow();

//ÇóÁ½¶ËµãËùÔÚÇøºÅcode

for(i=0;i

{

intc=0;

if(ptset[i].x

elseif(ptset[i].x>XR)c=c|RIGHT;

if(ptset[i].y>YB)c=c|BOTTOM;

elseif(ptset[i].y

code1=c;

c=0;

if(ptset[i+1].x

elseif(ptset[i+1].x>XR)c=c|RIGHT;

if(ptset[i+1].y>YB)c=c|BOTTOM;

elseif(ptset[i+1].y

code2=c;

//Ï߶ÎÓëÇøÓòµÄÏཻÇé¿ö

if(code1!

=0&&code2!

=0&&(code1&code2)==0)

{

if((LEFT&code1)!

=0)//Ï߶ÎÓë×ó±ß½çÏཻ

{

x=XL;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((RIGHT&code1)!

=0)//Ï߶ÎÓëÓұ߽çÏཻ

{

x=XR;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((BOTTOM&code1)!

=0)//Ï߶ÎÓëϱ߽çÏཻ

{

y=YB;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset[i+1].y-ptset[i+1].y);

}

elseif((TOP&code1)!

=0)//Ï߶ÎÓëÉϱ߽çÏཻ

{

y=YT;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset[i+1].y-ptset[i].y);

}

ptset[i].x=(long)x;

ptset[i].y=(long)y;

if((LEFT&code2)!

=0)//Ï߶ÎÓë×ó±ß½çÏཻ

{

x=XL;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((RIGHT&code2)!

=0)//Ï߶ÎÓëÓұ߽çÏཻ

{

x=XR;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((BOTTOM&code2)!

=0)//Ï߶ÎÓëϱ߽çÏཻ

{

y=YB;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset[i+1].y-ptset[i+1].y);

}

elseif((TOP&code2)!

=0)//Ï߶ÎÓëÉϱ߽çÏཻ

{

y=YT;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset[i+1].y-ptset[i].y);

}

ptset[i+1].x=(long)x;

ptset[i+1].y=(long)y;

pDC->MoveTo(ptset[i].x,ptset[i].y);

pDC->LineTo(ptset[i+1].x,ptset[i+1].y);

}

if(code1==0&&code2==0)

{pDC->MoveTo(ptset[i].x,ptset[i].y);

pDC->LineTo(ptset[i+1].x,ptset[i+1].y);

}

if(code1==0&&code2!

=0)

{

pDC->MoveTo(ptset[0].x,ptset[0].y);

if((LEFT&code2)!

=0)//Ï߶ÎÓë×ó±ß½çÏཻ

{

x=XL;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((RIGHT&code2)!

=0)//Ï߶ÎÓëÓұ߽çÏཻ

{

x=XR;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((BOTTOM&code2)!

=0)//Ï߶ÎÓëϱ߽çÏཻ

{

y=YB;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset[i+1].y-ptset[i+1].y);

}

elseif((TOP&code2)!

=0)//Ï߶ÎÓëÉϱ߽çÏཻ

{

y=YT;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset[i+1].y-ptset[i].y);

}

ptset[i+1].x=(long)x;

ptset[i+1].y=(long)y;

pDC->LineTo(ptset[i+1].x,ptset[i+1].y);

}

if(code1!

=0&&code2==0)

{

pDC->MoveTo(ptset[i+1].x,ptset[i+1].y);

if((LEFT&code1)!

=0)//Ï߶ÎÓë×ó±ß½çÏཻ

{

x=XL;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((RIGHT&code1)!

=0)//Ï߶ÎÓëÓұ߽çÏཻ

{

x=XR;

y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset[i+1].x-ptset[i].x);

}

elseif((BOTTOM&code1)!

=0)//Ï߶ÎÓëϱ߽çÏཻ

{

y=YB;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset[i+1].y-ptset[i+1].y);

}

elseif((TOP&code1)!

=0)//Ï߶ÎÓëÉϱ߽çÏཻ

{

y=YT;

x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset[i+1].y-ptset[i].y);

}

ptset[i].x=(long)x;

ptset[i].y=(long)y;

pDC-

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1