• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#后台画图保存为ipg/png的文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

        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("完成");
        }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
将C#编译为原生机器码发布时间:2022-07-10
下一篇:
C#点击按钮关闭当前窗体打开另一个窗体。发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap