• GDI+绘制简单的图形


    protected void Page_Load(object sender, EventArgs e)
            {
                /*
                    首先需要引用的命名空间是:System.Drawing;
                */
                GraphicsImage();
            }
    
            private void GraphicsImage()
            {
                int width = 800, hight = 400;
                Bitmap image = new Bitmap(width, hight);
                Graphics g = Graphics.FromImage(image);  //创建一个高200,宽440的画布
    
                try
                {
                    g.Clear(Color.LightBlue);   //清空背景色
    
                    /*在画布上写字*/
                    Font font1 = new Font("宋体", 10);  //设置字体类型和大小
                    Brush brush = new SolidBrush(Color.Black);  //设置画刷颜色           
                    g.DrawString("我的GDI+测试", font1, brush, 100, 20);
    
                    Pen pen = new Pen(Color.Brown, 1);  //创建画笔对象
    
                    /*在画布上画线*/
                    g.DrawLine(pen, 4, 80, 600, 80);  //绘制直线
    
                    /*在画布上画矩形*/
                    g.DrawRectangle(pen, 100, 120, 45, 100);  //绘制矩形
    
                    /*在画布上画多边形*/
                    Point[] points = new Point[5];
                    points[0].X = 300; points[0].Y = 60;
                    points[1].X = 250; points[1].Y = 80;
                    points[2].X = 300; points[2].Y = 100;
                    points[3].X = 350; points[3].Y = 100;
                    points[4].X = 600; points[4].Y = 80;
                    g.DrawPolygon(pen, points); //绘制多边形
    
                    g.DrawEllipse(pen, 50, 60, 80, 80);
                    //绘制椭圆形
                    g.DrawEllipse(pen, 150, 80, 100, 40);
                    //绘制扇形
                    g.DrawPie(pen, 270, 60, 100, 100, 180, 130);
    
    
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                    Response.ClearContent();
                    Response.ContentType = "image/Gif";
                    Response.BinaryWrite(ms.ToArray());
                }
                catch (Exception ms)
                {
                    Response.Write(ms.Message);
                }
            }
    

      

  • 相关阅读:
    C# WinForm dataGridView 技巧小结
    Win7设置局域网共享
    vs2010快捷键大全
    C# WebBrowser.DocumentCompleted 多次调用解决方法
    为应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制
    VB高清图标制作方法
    sqlite 中文排序
    一个vbs文件将指定文件夹下的文件名输出到指定文件夹下
    用DOS命令获取文件列表
    文件搜索神器 Everything
  • 原文地址:https://www.cnblogs.com/yxyht/p/2717440.html
Copyright © 2020-2023  润新知