zoukankan      html  css  js  c++  java
  • Graphics.SetClip 用法介绍

    1.Graphics 对象做为GDI+ 图形绘制接口,其对绘制区域剪辑,通过 SetClip() 方法实现。 

    比较常用 方法如: SetClip(Rectangle, CombineMode)

    Rectangle :选择区域范围

    CombineMode: Rectangle 所代表区域与Graphics 已选择范围之间作用关系,如 交集,并集,或者替换等,详细介绍:

     public enum CombineMode
        {
            //
            // 摘要:
            //     另一种将替换为一个剪辑区域。
            Replace = 0,
            //
            // 摘要:
            //     通过采用它们的交集组合两个剪辑区域。
            Intersect = 1,
            //
            // 摘要:
            //     通过采用这两者的 union 组合两个剪辑区域。
            Union = 2,
            //
            // 摘要:
            //     两个剪辑区域是组合采取相应的区域括起,一项或在其他区域中,但不是能同时。
            Xor = 3,
            //
            // 摘要:
            //     指定正在从现有的区域中删除的新区域的结果替换为现有区域。 换言之,从现有区域中排除的新区域。
            Exclude = 4,
            //
            // 摘要:
            //     指定正在从新的区域中删除现有区域的结果替换为现有区域。 换言之,从新区域中排除现有的区域。
            Complement = 5
        }

    2.测试CombineMode 不同类型 效果:

    private void SetClipRectangleFCombine(PaintEventArgs e)
            {
                Graphics newGraphics = e.Graphics;
    
                if (state == 1)
                {
                    //左上角矩形
                    newGraphics.SetClip(new Rectangle(0, 0, 100, 100));
                }
                else if (state == 2)
                {
                    //右下角矩形
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100));
                }
                else if (state == 3)
                {
                    //通过采用这两者的 union 组合两个剪辑区域
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100), CombineMode.Replace);
                    newGraphics.SetClip(new Rectangle(0, 80, 100, 100), CombineMode.Union);
                }
                else if (state == 4)
                {
                    //两个剪辑区域是组合采取相应的区域括起,一项或在其他区域中,但不是能同时
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100), CombineMode.Replace);
                    newGraphics.SetClip(new Rectangle(0, 80, 100, 100), CombineMode.Xor);
                }
                else if (state == 5)
                {
                    //通过采用它们的交集组合两个剪辑区域
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100), CombineMode.Replace);
                    newGraphics.SetClip(new Rectangle(0, 80, 100, 100), CombineMode.Intersect);
                }
                else if (state == 6)
                {
                    //指定正在从新的区域中删除现有区域的结果替换为现有区域。 换言之,从新区域中排除现有的区域
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100), CombineMode.Replace);
                    newGraphics.SetClip(new Rectangle(0, 80, 100, 100), CombineMode.Complement);
                }
                else if (state == 7)
                {
                    //指定正在从现有的区域中删除的新区域的结果替换为现有区域。 换言之,从现有区域中排除的新区域
                    newGraphics.SetClip(new Rectangle(50, 50, 100, 100), CombineMode.Replace);
                    newGraphics.SetClip(new Rectangle(0, 80, 100, 100), CombineMode.Exclude);
                }
    
                e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 500);

                 //恢复Clip 为无限区域,重新绘制
                 //e.Graphics.ResetClip();
                 //e.Graphics.FillRectangle(new SolidBrush(Color.Black), 75, 75 , 200, 200);

            }

    3.运行结果:

    state:1

    state 2:

    state 3:

    state 4:

    state 5:

    state 6:

     state 7:

  • 相关阅读:
    【uniapp】改善中大型uniapp小程序项目开发体验
    vite试玩:老项目启动从6分钟到秒开
    修剪AST树减少webapck打包尺寸
    librispeech数据集下载
    语音识别性能评估方法
    2021.12.11 物联网考试
    2021.12.15 课程总结+加分项
    2021.12.9 观影大数据分析
    2021.12.8 Docker服务
    2021.12.10 阿里云服务器创建
  • 原文地址:https://www.cnblogs.com/howtrace/p/11491525.html
Copyright © 2011-2022 走看看