首页 > Windows开发 > 详细

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

时间:2014-10-20 16:43:19      阅读:457      评论:0      收藏:0      [点我收藏+]
  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#图片上画图+写字(菜鸟勿喷)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!