博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#后台画图保存为ipg/png的文件
阅读量:6680 次
发布时间:2019-06-25

本文共 3248 字,大约阅读时间需要 10 分钟。

        public void Exec1()

        {
            string imgurl = @"http://api.senwoo.com/Content/HeadPortrait/";
            string imgurl = @"E:\";//本地头像路径-------
           string  imgfile = @"E:\";//图片路径-----------
            //背景
            Image image = new Bitmap(new Bitmap(imgfile + @"Img\d.jpg"), 720, 496);
      
            #region 写字
            Font font = new Font("微软雅黑", 11); //字是什么样子的?
            Font font5 = new Font("微软雅黑", 9); //字是什么样子的?
            Font font1 = new Font("微软雅黑", 8); //字是什么样子的?  兰亭特黑简.TTF
            Font font2 = new Font("微软雅黑 粗体", 12); //字是什么样子的?
            Brush brush = Brushes.Orange; //用红色涂上我的字吧; Orange
            Brush white = Brushes.White;//白色的笔
            #endregion
            #region 获取数据库数据
            DataSet ds = Getdateset();
            DataTable tb = ds.Tables[0];
            #endregion
            #region 画图
            Graphics g = null;
            try
            {
                g = Graphics.FromImage(image);
            }
            catch (Exception e)
            {
                WriteLog(e.ToString());
                throw;
            }
            int i = 0;
            int num = 0;
            int a1 = 41;//控制第(4-10)名的x坐标
            int a2 = 36;//控制第(4-10)名的x坐标
            int a3 = 47;//控制第(4-10)名的x坐标
            int a4 = 65;//控制第(4-10)名的x坐标
            int a5 = 65;
            int x = 0; //第一 二 三 名的x坐标
            foreach (DataRow item in tb.Rows)
            {
              
                Image i1 = new Bitmap(imgurl + @"Img\d2.jpg");//头像
                if (Convert.ToInt32(item["D1"]) == 1)
                {
                    //第一名
                    g.DrawImage(i1, 286, 112, 129, 129);
                    g.DrawImage(new Bitmap(imgfile + @"Img\2.png"), 279, 100, 145, 174);
                    g.DrawString(item["sdgroupname"].ToString(), font, white, 326, 227);
                    if (item["stname"].ToString().Length == 3)
                    { x = 331; }
                    else
                    { x = 317; }
                    g.DrawString(item["stname"].ToString(), font5, brush, x, 248);
                }
                else if (Convert.ToInt32(item["D1"]) == 2)
                {
                    #region MyRegion
                    g.DrawImage(i1, 85, 139, 129, 129);
                    g.DrawImage(new Bitmap(imgfile + @"\img\3.png"), 79, 130, 145, 174);
                    if (item["sdgroupname"].ToString().Length == 3)
                    {
                        x = 126;
                    }
                    else
                    {
                        x = 119;
                    }
                    g.DrawString(item["sdgroupname"].ToString(), font, white, x, 256);
                    if (item["stname"].ToString().Length == 3)
                        x = 130;
                    else
                        x = 120;
                    g.DrawString(item["stname"].ToString(), font5, brush, x, 277);
                    #endregion
                }
                else if (Convert.ToInt32(item["D1"]) == 3)
                {
                    #region MyRegion
                    WriteLog("开c3");
                    g.DrawImage(i1, 485, 139, 129, 129);
                    g.DrawImage(new Bitmap(imgfile + @"Img\5.png"), 479, 130, 145, 174);
                    if (item["sdgroupname"].ToString().Length == 3)
                    {
                        x = 523;
                    }
                    else
                    {
                        x = 535;
                    }
                    g.DrawString(item["sdgroupname"].ToString(), font, white, x, 256);
                    if (item["stname"].ToString().Length == 3)
                        x = 527;
                    else
                        x = 522;
                    g.DrawString(item["stname"].ToString(), font5, brush, x, 276);
                    #endregion
                }
                else
                {
                    g.DrawImage(i1, a1 + num, 353, 79, 79);
                    g.DrawImage(new Bitmap(imgfile + @"Img\c.png"), a2 + num, 340, 92, 124);
                    if (i == 6)
                    {
                        a3 = a3 - 5;
                    }
                    g.DrawString((4 + i).ToString(), font2, white, a3 + num, 421);
                    g.DrawString(item["sdgroupname"].ToString(), font1, white, a4 + num, 423);
                    g.DrawString(item["stname"].ToString(), font1, brush, a5 + num, 438);
                    num += 92;
                    i++;
                }
            }
            #endregion
            WriteLog("开始保存");
            #region MyRegion
            //写好了,我要把我的作品收藏起来
            try
            {
                g.BeginContainer();
                string imgName = GetImgName();//原来的名字
                string Route = "C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\Download\\Picture\\Operator\\";//服务器
                Route = "E:\\Img\\";//本地路径
                image.Save(Route + imgName);//保存在本地
                string newImgName = Guid.NewGuid() + ".jpg";
                //System.IO.File.Move(Route + imgName, Route + newImgName); //修改名称
                //updateImgName(newImgName);
            }
            catch (Exception ex)
            {
                throw;
            }
            #endregion
            WriteLog("完成");
        }

转载于:https://www.cnblogs.com/cl1006/p/6305518.html

你可能感兴趣的文章
ubuntu 为rabbitmq安装web插件管理界面(为了远程查看rabbitmq) 分类...
查看>>
1.4 注册系统的逻辑与结构
查看>>
NOIP模拟2017.6.11解题报告
查看>>
Scramble String
查看>>
Linux基础:CentOS安装python3.7
查看>>
Daily Scrum: 2012/11/27
查看>>
vue学习中v-if和v-show一起使用的问题
查看>>
获取一个月前的当前时间
查看>>
第三期 预测——1.简介
查看>>
behavior planning——12.example cost funtion -lane change penalty
查看>>
基于 Spring + Atomikos + Mybatis的多数据源配置demo
查看>>
随笔-刚毕业找工作的点滴(程序员)
查看>>
利用poi3.8中SXSSFWorkbook实现大数据量导出excel
查看>>
day34-1 面向对象概述
查看>>
GCD之dispatch queue
查看>>
【Oracle】-初识PL/SQL
查看>>
黄聪:超实用的PHPExcel[导入][导出]实现方法总结
查看>>
模板变量,过滤器和静态文件引入
查看>>
Oracle 中的 Schema
查看>>
Web APi之认证(Authentication)两种实现方式后续【三】(十五)
查看>>