1
1using System;
2
2using System.Data;
3
3using System.Configuration;
4
4using System.Web;
5
5using System.Web.Security;
6
6using System.Web.UI;
7
7using System.Web.UI.WebControls;
8
8using System.Web.UI.WebControls.WebParts;
9
9using System.Web.UI.HtmlControls;
10
10using System.Drawing;
11
11namespace WebHelper
12
12
{
13
13
14
14 /**//**//**//// <summary>
15
15 /**//// ImageHelper 的摘要说明
16
16 /**//// </summary>
17
17 public class ImageHelper
18
18
{
19
19 public ImageHelper()
20
20
{
21
21 //
22
22 // TODO: 在此处添加构造函数逻辑
23
23 //
24
24 }
25
25 Image水印Image水印#region Image水印
26
26 /**//**//**//// <summary>
27
27 /**//// 写入图像水印
28
28 /**//// </summary>
29
29 /**//// <param name="str">水印字符串</param>
30
30 /**//// <param name="filePath">原图片位置</param>
31
31 /**//// <param name="savePath">水印加入后的位置</param>
32
32 /**//// <returns></returns>
33
33 public string CreateBackImage(System.Web.UI.Page pageCurrent, string str, string filePath, string savePath, int x, int y)
34
34
{
35
35 System.Drawing.Image img = System.Drawing.Image.FromFile(pageCurrent.MapPath(filePath));
36
36 //创建图片
37
37 Graphics graphics = Graphics.FromImage(img);
38
38 //指定要绘制的面积
39
39 graphics.DrawImage(img, 0, 0, img.Width, img.Height);
40
40 //定义字段和画笔
41
41 Font font = new Font("黑体", 16);
42
42 Brush brush = new SolidBrush(Color.Yellow);
43
43 graphics.DrawString(str, font, brush, x, y);
44
44 //保存并输出图片
45
45 img.Save(pageCurrent.MapPath(savePath), System.Drawing.Imaging.ImageFormat.Jpeg);
46
46 return savePath;
47
47
48
48 }
49
49 #endregion
50
50 Image自动缩小Image自动缩小#region Image自动缩小
51
51 /**//**//**//// <summary>
52
52 /**//// 缩小图片到指定的大小
53
53 /**//// </summary>
54
54 /**//// <param name="strOldPic">
55
55 /**//// 原图片的位置
56
56 /**//// </param>
57
57 /**//// <param name="strNewPic">
58
58 /**//// 缩小后的图片位置
59
59 /**//// </param>
60
60 /**//// <param name="intWidth">
61
61 /**//// 宽度
62
62 /**//// </param>
63
63 /**//// <param name="intHeight">
64
64 /**//// 高度
65
65 /**//// </param>
66
66 public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
67
67
{
68
68
69
69 System.Drawing.Bitmap objPic, objNewPic;
70
70 try
71
71
{
72
72 objPic = new System.Drawing.Bitmap(strOldPic);
73
73 objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
74
74 objNewPic.Save(strNewPic);
75
75
76
76 }
77
77 catch (Exception exp)
{ throw exp; }
78
78 finally
79
79
{
80
80 objPic = null;
81
81 objNewPic = null;
82
82 }
83
83 }
84
84
85
85 public void SmallPic(string strOldPic, string strNewPic, int intWidth)
86
86
{
87
87
88
88 System.Drawing.Bitmap objPic, objNewPic;
89
89 try
90
90
{
91
91 objPic = new System.Drawing.Bitmap(strOldPic);
92
92 int intHeight = Convert.ToInt32(((intWidth * 1.0) / (objPic.Width * 1.0)) * objPic.Height);
93
93 objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
94
94 objNewPic.Save(strNewPic, objPic.RawFormat);
95
95
96
96 }
97
97 catch (Exception exp)
{ throw exp; }
98
98 finally
99
99
{
100
100 objPic = null;
101
101 objNewPic = null;
102
102 }
103
103 }
104
104
105
105 //public void SmallPic(string strOldPic, string strNewPic, int intHeight)
106
106 //{
107
107
108
108 // System.Drawing.Bitmap objPic, objNewPic;
109
109 // try
110
110 // {
111
111 // objPic = new System.Drawing.Bitmap(strOldPic);
112
112 // int intWidth = Convert.ToInt32(((intHeight * 1.0) / objPic.Height) * objPic.Width);
113
113 // objNewPic = new System.Drawing.Bitmap(objPic, intWidth, intHeight);
114
114 // objNewPic.Save(strNewPic, objPic.RawFormat);
115
115
116
116 // }
117
117 // catch (Exception exp) { throw exp; }
118
118 // finally
119
119 // {
120
120 // objPic = null;
121
121 // objNewPic = null;
122
122 // }
123
123 //}
124
124 #endregion
125
125
126
126 }
127
127}
posted @
2008-10-07 12:26
Elliott.Dong
阅读(
449)
评论()
收藏
举报