zoukankan      html  css  js  c++  java
  • C# 绘图三种方式

    如果你想在窗体上进行绘画。通常会使用以下方法.
    方法1,利用控件或窗体的paint事件中的painEventArgs
    private void form1_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;//创建画板,
    }
    方法2直接重载控件或窗体的OnPaint方法
    protected override void OnPaint(PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    }
    方法3调用某控件的CreateGraphics方法
    Graphics g = this.CreateGraphics();
    
    方法4 调用Graphics类的FromImage静态方法
    在需要更改已存在的图像时,通常会使用此方法
    Image img = Image.FromFile("g1.jpg");//建立Image对象
    Graphics g = Graphics.FromImage(img);//创建Graphics对象
    public Bitmap Create(int[] arry)
            {
                //获得数组中最大值
                int max = 0;
                for (int i = 0; i < arry.Length; i++)
                {
                    if (arry[i] > max)
                        max = arry[i];
                }
                Bitmap bitmap = new Bitmap(arry.Length, max+10);
                Graphics g = Graphics.FromImage(bitmap);//创建Graphics对象
                g.Clear(Color.White);
                Pen curPen = new Pen(Brushes.Black, 1);
    
                // g.DrawLine(curPen, 10, 0, 10, 30); //划线 ; 水平坐标形同 10,0,10,30;  y坐标不同
    
                for (int i = 0; i < arry.Length; i++)
                {
                    g.DrawLine(curPen, i, arry[i], i, 0); //划线 ; 水平坐标形同 10,0,10,30;  y坐标不同
                }
    
                return bitmap;
            }
  • 相关阅读:
    【设计模式】六大原则
    【HTML5】表单属性
    【HTML5】表单元素
    【HTML5】input类型
    【HTML5】Server-Sent服务器发送事件
    【HTML5】Web Workers
    【HTML5】Application Cache应用程序缓存
    【HTML5】Web存储
    【HTML5】地理定位
    【HTML5】Canvas和SVG的区别
  • 原文地址:https://www.cnblogs.com/enych/p/10544592.html
Copyright © 2011-2022 走看看