C#:使用GDI+创建一张图片并保存到本地

            // 创建一个新的图片对象  
            Bitmap image = new Bitmap(500, 500); // 宽度和高度为200像素  
            Pen pen = new Pen(Color.Black);
            pen.Color = Color.Yellow;
            pen.Width = 3;

            // 获取图片的Graphics对象,用于绘制  
            Graphics graphics = Graphics.FromImage(image);

            // 设置背景色为白色  
            graphics.Clear(Color.White);

            // 绘制表格边框  
            graphics.DrawRectangle(Pens.Black, 50, 50, 400, 400);
            //graphics.DrawLine(Pens.Black, 50, 50, 50, 200);
            graphics.DrawLine(pen, 100, 50, 100, 200);
            graphics.DrawLine(pen, 150, 50, 150, 200);
            graphics.DrawLine(pen, 200, 50, 200, 200);
            graphics.DrawLine(pen, 250, 50, 250, 200);
            pen.Color = Color.Red;
            graphics.DrawLine(pen, 50, 100, 250, 100);
            graphics.DrawLine(pen, 50, 150, 250, 150);
            graphics.DrawLine(pen, 50, 200, 250, 200);
            graphics.DrawLine(pen, 50, 250, 250, 250);


            //绘制表格标题行
            graphics.DrawString("Column 1", new Font("Arial", 14), Brushes.Black, 60, 60);
            graphics.DrawString("Column 2", new Font("Arial", 14), Brushes.Black, 70, 80);
            graphics.DrawString("Column 3", new Font("Arial", 14), Brushes.Black, 80, 60);
            graphics.DrawString("Column 4", new Font("Arial", 14), Brushes.Black, 90, 80);
            graphics.DrawString("Column 5", new Font("Arial", 14), Brushes.Black, 100, 60);
            graphics.DrawString("Column 6", new Font("Arial", 14), Brushes.Black, 110, 80);
            // 绘制表格数据行  
            //graphics.DrawString("Data 1", new Font("Arial", 12), Brushes.Black, 70, 100);
            //graphics.DrawString("Data 2", new Font("Arial", 12), Brushes.Black, 70, 120);

            // 保存图片到文件  
            image.Save(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "MustFile\\" + "总结" + ".png"); //System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "MustFile\\"

            using (FileStream stream = new FileStream(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "MustFile\\" + "总结" + ".png", FileMode.Open, FileAccess.Read))
            {
                pictureBox2.Image = Image.FromStream(stream);
            }


            //pictureBox2.Image = Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "MustFile\\" + "总结" + ".png");

            // 释放Graphics和Bitmap资源  
            graphics.Dispose();
            image.Dispose();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值