首页 > 代码库 > 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#图片上画图+写字(菜鸟勿喷)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。