1usando Sistema;
2usando System.Data;
3usando System.Configuration;
4usando System.Web;
5usando System.Web.Security;
6usando System.Web.UI;
7usando System.Web.UI.WebControls;
8usando System.Web.UI.WebControls.WebParts;
9usando System.Web.UI.HtmlControls;
10usando System.Drawing;
11espaço de nomes WebHelper
12{
13
14 /**////
15 /// ImageHelper 的摘要说明
16 ///
17 classe pública ImageHelper
18 {
19 ImageHelper público()
20 {
21 //
22 // TODO: 在此处添加构造函数逻辑
23 //
24}
25 Imagem水印#region Imagem水印
26 /**////
27 /// 写入图像水印
28 ///
29 /// 水印字符串
30 /// 原图片位置
31 /// 水印加入后的位置
32 ///
33 string pública CreateBackImage (System.Web.UI.Page pageCurrent, string str, string filePath, string savePath, int x, int y)
34 {
35 System.Drawing.Image img = System.Drawing.Image.FromFile(pageCurrent.MapPath(filePath));
36 //创建图 foto
37 Gráficos gráficos = Graphics.FromImage(img);
38 //指定要绘制的面积
39 gráficos.DrawImage(img, 0, 0, img.Width, img.Height);
40 //定义字段和画笔
41 Fonte fonte = new Fonte("黑体", 16);
42 Pincel pincel = novo SolidBrush(Color.Yellow);
43 gráficos.DrawString(str, fonte, pincel, x, y);
44 //保存并输出图 foto
45 img.Save(pageCurrent.MapPath(savePath), System.Drawing.Imaging.ImageFormat.Jpeg);
46 retorne savePath;
47
48}
49 #regiãofinal
50 Imagem自动缩小#region Imagem自动缩小
51 /**////
52 /// 缩小图片到指定的大小
53 ///
54 ///
55 /// 原图片的位置
56 ///
57 ///
58 /// 缩小后的图片位置
59 ///
60 ///
61 /// 宽度
62 ///
63 ///
64 /// 高度
65 ///
66 public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
67 {
68
69 System.Drawing.Bitmap objPic, objNewPic;
70 tentativas
71 {
72 objPic = novo System.Drawing.Bitmap(strOldPic);
73 objNewPic = novo System.Drawing.Bitmap(objPic, intWidth, intHeight);
74 objNewPic.Save(strNewPic);
75
76}
77 catch (Exceção exp) { throw exp; }
78 finalmente
79 {
80 objPic = nulo;
81 objNewPic = nulo;
82}
83}
84
85 public void SmallPic(string strOldPic, string strNewPic, int intWidth)
86 {
87
88 System.Drawing.Bitmap objPic, objNewPic;
89 tentar
90 {
91 objPic = novo System.Drawing.Bitmap(strOldPic);
92 int intHeight = Convert.ToInt32(((intWidth * 1.0) / (objPic.Width * 1.0)) * objPic.Height);
93 objNewPic = novo System.Drawing.Bitmap(objPic, intWidth, intHeight);
94 objNewPic.Save(strNewPic, objPic.RawFormat);
95
96}
97 catch (Exceção exp) { throw exp; }
98 finalmente
99 {
100 objPic = nulo;
101 objNewPic = nulo;
102}
103}
104
105 //public void SmallPic(string strOldPic, string strNewPic, int intHeight)
106 //{
107
108 //System.Drawing.Bitmap objPic, objNewPic;
109 //tente
110 // {
111 // objPic = new System.Drawing.Bitmap(strOldPic);
112 // int intWidth = Convert.ToInt32(((intHeight * 1.0) / objPic.Height) * objPic.Width);
113 // objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
114 //objNewPic.Save(strNewPic, objPic.RawFormat);
115
116 // }
117 // catch (Exceção exp) { throw exp; }
118 // finalmente
119 // {
120 // objPic = null;
121 // objNewPic = null;
122 // }
123//}
124 #regiãofinal
125
126}
127}
http://www.cnblogs.com/chu888chu888/archive/2007/01/09/615803.html