C# 图片添加旋转字体文字,实现图片装逼功能
2016-03-21 13:35
836 查看
public ActionResult View1() { string path = AppDomain.CurrentDomain.BaseDirectory + "font\\向佳红毛笔行书.ttf"; //选择字体文件 string ItemPath = AppDomain.CurrentDomain.BaseDirectory + "Image\\2.jpg"; //选择图片 string str = Request["name"]; //获取 网页网址 ?name= 也就是名字 if (System.IO.File.Exists(ItemPath)) { System.IO.MemoryStream img = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(ItemPath)); Bitmap bmp = new Bitmap(img); Graphics g = Graphics.FromImage(bmp); //读取字体文件并添加字体文件 PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(path); Font font = new Font(pfc.Families[0], 38); SolidBrush sbrush = new SolidBrush(Color.FromArgb(205,0,0,0)); PointF point = new PointF(317, 790); // 绘制围绕点旋转的文本 StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; Matrix mtxSave = g.Transform; Matrix mtxRotate = g.Transform; mtxRotate.RotateAt(5f, point); // 旋转角度和平移 g.Transform = mtxRotate; g.DrawString(str, font, sbrush, point, format); //处理图片, (名字,字体样式,颜色,文字在图片上的位置,旋转角度 MemoryStream ms = new MemoryStream(); //if (System.IO.File.Exists(ItemPath)) //{ // System.IO.File.Delete(TmpPath); //} bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); bmp.Dispose(); return File(ms.ToArray(), "image/jpeg"); } else { return View(); } }demo下载: 链接: http://pan.baidu.com/s/1bockKDT 密码: bxxm
相关文章推荐
- VS2015安装&简单的C#单元测试
- C#中DropDownList显示默认值
- C#后台无刷新页面弹出alert方法
- C#程序代码分析(第三周)
- C#ListView控件的相关用法
- C#中的Nullable及??操作符
- 转:C#中TransactionScope的使用方法和原理
- 《CLR Via C#》改变Visual Studio中Output Window输出内容的详细程度
- C#中的计时器
- C#中volatile和synchronized
- 《CLR Via C#》 C# Compiler
- 平均分配问题
- C#日期时间格式化
- C# typeof() 和 GetType()区别
- C#语言之“实例化的正确顺序”
- C#数组
- C#程序编码规范
- C#的一些小知识
- C#的一些小知识
- C# 基于SharpPcap的局域网数据包捕获 之二 监听代码