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:

  • 相关阅读:
    《快速开发》通过Maven创建WebService项目Hello World!
    《常见问题集》Eclipse
    《常见问题集》Maven
    Eclipse + Jersey 发布RESTful WebService(一)了解Maven和Jersey,创建一个WS项目(成功!)
    Java2WSDL 和 WSDL2Java(Axis)
    Eclipse + Apache Axis2 发布RESTful WebService(一)基础知识
    Eclipse + Apache Axis2 发布SOAP WebService(三)第一个程序Hello Axis2 SOAP!
    Eclipse + Apache Axis2 发布RESTful WebService(三)第一个程序Hello Axis2 !(未成功)
    Eclipse + Apache Axis2 发布RESTful WebService(二)配置开发环境
    学习 JSP:第三步 JSP基础(未完)
  • 原文地址:https://www.cnblogs.com/howtrace/p/11491525.html
Copyright © 2011-2022 走看看