关于VC6.0中GDI+,如何设置剪切区的问题.
实现功能:
给出两个以上的任意点(设备坐标),范围值(这条线的两侧,我们说成左侧或右侧,也可以理解成内侧,外侧)设备坐标的大小;比如说有三个点P1,P2,P3,连成一条折线;要求:
当选择左侧显示时,需要以这三个点的连线为基准像线的左侧按照指定的范围(比如20)扩充,
实际上就是显示了一条宽度为20的一条折线,就是说P1,P2,P3点正好在这条宽线的最外侧,怎么实现啊??和直接画一条宽度为20 的折线不同,因为直接画的话P1,P2,P3在这条宽线的中心了(所以不能直接画);所以我想到用GDI+中设置剪切区的方法,如下:
但是在折线的两头显示的不正确,我考虑是剪切区设置不对,大家帮我看看。void MyClass::OnDraw(CDC*pDC)
{
CPoint pts[3];
pts[0] = CPoint(50,50);
pts[1] = CPoint(200,100);
pts[2] = CPoint(40,80);//扩充大小
int nSize = 20;//左或右
bool bLeft = true; Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Color clrPen(180,r,g,b);
Pen penDraw(clrPen,nSize );
Color clrFill(100,255,255,255);//背景颜色
penDraw.SetAlignment(PenAlignmentCenter);
GraphicsPath myGraphicsPath(FillModeAlternate);
myGraphicsPath.AddLines(pts, 3);
GraphicsPath myClipPath(FillModeAlternate);
myClipPath.AddLines(pts, 3); penDraw.SetWidth (nSize *2);
if(bLeft)
graphics.SetClip (&myClipPath,CombineModeExclude);
else
graphics.SetClip (&myClipPath,CombineModeIntersect); graphics.DrawPath(&penDraw,&myGraphicsPath);}
我做的意思是,画一条宽度为nSize*2的线,然后向左或向右剪切一半来实现;但是这样做出来的效果不对,在线的两头多出来两个三角形填充区域。
这是为什么啊?
希望大家能明白我的意思,如果有愿意帮助的又不明白我说的意思,把邮箱留下,我可以给你发个图片,一看就明白了。
实现功能:
给出两个以上的任意点(设备坐标),范围值(这条线的两侧,我们说成左侧或右侧,也可以理解成内侧,外侧)设备坐标的大小;比如说有三个点P1,P2,P3,连成一条折线;要求:
当选择左侧显示时,需要以这三个点的连线为基准像线的左侧按照指定的范围(比如20)扩充,
实际上就是显示了一条宽度为20的一条折线,就是说P1,P2,P3点正好在这条宽线的最外侧,怎么实现啊??和直接画一条宽度为20 的折线不同,因为直接画的话P1,P2,P3在这条宽线的中心了(所以不能直接画);所以我想到用GDI+中设置剪切区的方法,如下:
但是在折线的两头显示的不正确,我考虑是剪切区设置不对,大家帮我看看。void MyClass::OnDraw(CDC*pDC)
{
CPoint pts[3];
pts[0] = CPoint(50,50);
pts[1] = CPoint(200,100);
pts[2] = CPoint(40,80);//扩充大小
int nSize = 20;//左或右
bool bLeft = true; Graphics graphics(pDC->m_hDC);
graphics.SetSmoothingMode(SmoothingModeAntiAlias); Color clrPen(180,r,g,b);
Pen penDraw(clrPen,nSize );
Color clrFill(100,255,255,255);//背景颜色
penDraw.SetAlignment(PenAlignmentCenter);
GraphicsPath myGraphicsPath(FillModeAlternate);
myGraphicsPath.AddLines(pts, 3);
GraphicsPath myClipPath(FillModeAlternate);
myClipPath.AddLines(pts, 3); penDraw.SetWidth (nSize *2);
if(bLeft)
graphics.SetClip (&myClipPath,CombineModeExclude);
else
graphics.SetClip (&myClipPath,CombineModeIntersect); graphics.DrawPath(&penDraw,&myGraphicsPath);}
我做的意思是,画一条宽度为nSize*2的线,然后向左或向右剪切一半来实现;但是这样做出来的效果不对,在线的两头多出来两个三角形填充区域。
这是为什么啊?
希望大家能明白我的意思,如果有愿意帮助的又不明白我说的意思,把邮箱留下,我可以给你发个图片,一看就明白了。
penDraw.SetAlignment(PenAlignmentInset)
我试了,不行啊,你留个Email啊,我给你发邮件你看下啊,谢谢;
Status SetAlignment(PenAlignment penAlignment);
设置为内对齐,其输入参数取枚举类型PenAlignment的符号常量:
typedef enum {
PenAlignmentCenter = 0, // 中心对齐(缺省值)
PenAlignmentInset = 1 // 内对齐
} PenAlignment;例如:
Graphics graph(pDC->m_hDC);
Rect rect(20, 20, 300, 200);
Pen pen(Color::Green, 30), redPen(Color::Red);
graph.DrawEllipse(&pen, rect);
graph.DrawRectangle(&redPen, rect);
pen.SetAlignment(PenAlignmentInset); // 内对齐
graph.TranslateTransform(340, 0);
graph.DrawEllipse(&pen, rect);
graph.DrawRectangle(&redPen, rect);
可以帮你看看。
不行啊朋友,你这样平移,p1,p2,p3点位置就不对了啊。
我给你发了邮件,麻烦有时间看下。有点问题请教。