首页 > 代码库 > C#图片上画图+写字(菜鸟勿喷)

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

  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#图片上画图+写字(菜鸟勿喷)