zjn15000 2021-09-13 20:33 采纳率: 0%
浏览 22

在非线性的闭合区域内填充颜色

img

想在以上非线性的闭合区域内填充颜色,需要怎么弄?


void DrawRadicalSlider::OnPaint()
{
    CPen pen;
    CPen *my_old_pen;
    //CBrush brush, *p_old_brush;
    CPaintDC dc(this);
    CPoint center;
    CRect rect;
    int out_radius = 200;// 设置外圈圆弧半径
    int inter_radius = 150; // 设置内圈圆弧半径
    CDC *pdc = GetDC();

    pen.CreatePen(PS_SOLID,2,RGB(0,0,0));
    my_old_pen = dc.SelectObject(&pen);
    //brush.CreateSolidBrush(RGB(0,0,0));
    //p_old_brush = dc.SelectObject(&brush);

    //dc.MoveTo(0,0);
    //dc.LineTo(0,100);
    //dc.LineTo(100,100);
    //dc.LineTo(100,0);
    //dc.LineTo(0,0);
    GetClientRect(rect); // 获取窗口矩形
    center = rect.CenterPoint(); // 获取窗口中心位置坐标
     
    float rad = 120 * pi / 180;
    dc.Arc(center.x - out_radius, center.y - out_radius, 
        center.x + out_radius, center.y + out_radius,
        center.x, center.y - out_radius,
        (center.x - sin(rad) * out_radius), (center.y - cos(rad) * out_radius));  
    dc.Arc(center.x - inter_radius, center.y - inter_radius, 
        center.x + inter_radius, center.y + inter_radius,
        center.x, center.y - inter_radius,
        (center.x - sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.MoveTo(center.x, center.y - inter_radius);
    dc.LineTo(center.x, center.y - out_radius);
    dc.MoveTo((center.x - sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.LineTo((center.x - sin(rad) * out_radius), (center.y - cos(rad) * out_radius));

    center.x = center.x + 5; // 圆心向右偏移5
    dc.Arc(center.x - out_radius, center.y - out_radius, 
        center.x + out_radius, center.y + out_radius,
        (center.x + sin(rad) * out_radius), (center.y - cos(rad) * out_radius),
        center.x, center.y - out_radius);
    dc.Arc(center.x - inter_radius, center.y - inter_radius, 
        center.x + inter_radius, center.y + inter_radius,
        (center.x + sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius),
        center.x, center.y - inter_radius);
    dc.MoveTo(center.x, center.y - inter_radius);
    dc.LineTo(center.x, center.y - out_radius);
    dc.MoveTo((center.x + sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.LineTo((center.x + sin(rad) * out_radius), (center.y - cos(rad) * out_radius));

    center.x = center.x - 2.5;
    center.y = center.y + 5; // 圆心向下偏移5
    dc.Arc(center.x - out_radius, center.y - out_radius, 
        center.x + out_radius, center.y + out_radius,
        (center.x - sin(rad) * out_radius), (center.y - cos(rad) * out_radius),
        (center.x + sin(rad) * out_radius), (center.y - cos(rad) * out_radius));  
    dc.Arc(center.x - inter_radius, center.y - inter_radius, 
        center.x + inter_radius, center.y + inter_radius,
        (center.x - sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius),
        (center.x + sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.MoveTo((center.x - sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.LineTo((center.x - sin(rad) * out_radius), (center.y - cos(rad) * out_radius));
    dc.MoveTo((center.x + sin(rad) * inter_radius), (center.y - cos(rad) * inter_radius));
    dc.LineTo((center.x + sin(rad) * out_radius), (center.y - cos(rad) * out_radius));
    
    //dc.SelectObject(p_old_brush);

    DeleteObject(dc);
}
  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-09-13 22:30
    关注

    具体是指哪个区域啊?能用颜色标识一下吗?
    可以用CDC里path来表示封闭区域的路径,然后FillPath可以填充颜色
    就是先
    dc.BeginPath();
    然后dc.MoveTo,LineTo之类的绘制路径,最后dc.EndPath()结束路径
    然后dc.FillPath()进行填充。参考如下:

    brush2.CreateSolidBrush(RGB(255,0,0));//纯色
    dc.BeginPath();
    dc.Polyline(pt,3);  
    dc.EndPath();
    dc.SelectObject(&brush2);
    dc.FillPath();
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 9月13日

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。