读本地图像文件,在上面写一些文件,再传到WWW服务器上
1 public class ImgExtends 2 3 { 4 5 /// <summary> 6 7 /// 像本地图像文件上写字,并上传本地服务器 8 9 /// </summary> 10 11 /// <param name="imgserverurl">Web服务器上的图片路径</param> 12 13 /// <param name="title">图片上的文字</param> 14 15 /// <returns></returns> 16 17 public static string GetImg(string imgserverurl, string title) 18 19 { 20 21 try 22 23 { 24 25 if (!string.IsNullOrEmpty(imgserverurl)) 26 27 { 28 29 string Path = System.Web.HttpContext.Current.Server.MapPath("/Upload/Product"); 30 31 string FileName = "\\" + VCommons.Utils.GetNewGuid() + ".jpg"; 32 33 34 35 Image img = Image.FromFile(imgserverurl); 36 37 int width = img.Width; 38 39 int height = img.Height; 40 41 42 43 Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); 44 45 bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution); 46 47 48 49 Graphics grap = Graphics.FromImage(bitmap); 50 51 grap.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 52 53 grap.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel); 54 55 56 57 Font font = new Font("微软雅黑", 24, FontStyle.Bold); 58 59 60 61 SolidBrush solid = new SolidBrush(Color.Turquoise); 62 63 64 65 StringFormat format = new StringFormat(); 66 67 format.Alignment = StringAlignment.Near; 68 69 grap.DrawString(title, font, solid, 25, 18, format); 70 71 grap.Dispose(); 72 73 74 75 bitmap.Save(Path + FileName, ImageFormat.Jpeg); 76 77 return "http://" + RequestHelper.GetHost() + "/Upload/Product" + FileName; 78 79 } 80 81 else 82 83 { 84 85 return string.Empty; 86 87 } 88 89 90 91 } 92 93 catch (Exception) 94 95 { 96 97 return string.Empty; 98 99 } 100 101 } 102 103 }
分类:
其它 / 面向对象
, 其它 / ASP.NET
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示