码迷,mamicode.com
首页 > Windows程序 > 详细

C#图片上画图+写字(菜鸟勿喷)

时间:2014-10-20 16:43:33      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   div   on   

  public void InitPage(string url, UserInfoBusinessCardView model) {
            string path = Path.GetDirectoryName(url);
            string filename = DateTime.Now.ToString("yyyyMMddhhmmss");
            using (Image bigImage = Image.FromFile(url)) {
                using (Image smallImg = Image.FromFile(model.HeadPhotos)) {
                    using (Graphics g = Graphics.FromImage(bigImage)) {
                        int x = bigImage.Width - smallImg.Width;
                        int y = bigImage.Height - smallImg.Height;
                        //添加头像
                        g.DrawImage(smallImg, 0, 0, smallImg.Width, smallImg.Height);
                        SolidBrush drawBush = new SolidBrush(Color.Red);
                        Font drawFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Millimeter);
                        string newPath = path + "\\" + filename + ".png";
                        //写汉字
                        g.DrawString(model.Name, drawFont, drawBush, 10, 10);
                        g.DrawString(model.Title1String + model.Title2String, drawFont, drawBush, 50, 50);
                        bigImage.Save(newPath, System.Drawing.Imaging.ImageFormat.Png);
                        if (System.IO.File.Exists(newPath)) {
                            //return newPath;
                        }
                        else {
                            //  return null;
                        }
                    }
                }
            }
        }

  //调用的地方

 public ActionResult PPP() {
            string url = Request.MapPath("~/Images/4560.jpg");
            string heda = Request.MapPath("~/Images/745.jpg");
            UserInfoBusinessCardView model = new UserInfoBusinessCardView();
            model.Name = "刘建伟";
            model.Title1String = "XXXXXXXXX牛逼公司";
            model.Title2String = "码农";
            model.HeadPhotos = heda;
            InitPage(url, model);
            return View();
        }

 ///

C#图片上画图+写字(菜鸟勿喷)

标签:style   blog   color   io   os   ar   for   div   on   

原文地址:http://www.cnblogs.com/alphafly/p/4037409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!