楚广明的博客
教育不是灌溉,是点燃火焰
随笔 - 531, 文章 - 11, 评论 - 794, 引用 - 14
封装的一些实现图片水印与图片自动结合缩放的类
1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10
using
System.Drawing;
11
namespace
WebHelper
12
{
13
14
/**/
///
<summary>
15
///
ImageHelper 的摘要说明
16
///
</summary>
17
public
class
ImageHelper
18
{
19
public
ImageHelper()
20
{
21
//
22
//
TODO: 在此处添加构造函数逻辑
23
//
24
}
25
Image水印
#region
Image水印
26
/**/
///
<summary>
27
///
写入图像水印
28
///
</summary>
29
///
<param name="str">
水印字符串
</param>
30
///
<param name="filePath">
原图片位置
</param>
31
///
<param name="savePath">
水印加入后的位置
</param>
32
///
<returns></returns>
33
public
string
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
//
创建图片
37
Graphics graphics
=
Graphics.FromImage(img);
38
//
指定要绘制的面积
39
graphics.DrawImage(img,
0
,
0
, img.Width, img.Height);
40
//
定义字段和画笔
41
Font font
=
new
Font(
"
黑体
"
,
16
);
42
Brush brush
=
new
SolidBrush(Color.Yellow);
43
graphics.DrawString(str, font, brush, x, y);
44
//
保存并输出图片
45
img.Save(pageCurrent.MapPath(savePath), System.Drawing.Imaging.ImageFormat.Jpeg);
46
return
savePath;
47
48
}
49
#endregion
50
Image自动缩小
#region
Image自动缩小
51
/**/
///
<summary>
52
///
缩小图片到指定的大小
53
///
</summary>
54
///
<param name="strOldPic">
55
///
原图片的位置
56
///
</param>
57
///
<param name="strNewPic">
58
///
缩小后的图片位置
59
///
</param>
60
///
<param name="intWidth">
61
///
宽度
62
///
</param>
63
///
<param name="intHeight">
64
///
高度
65
///
</param>
66
public
void
SmallPic(
string
strOldPic,
string
strNewPic,
int
intWidth,
int
intHeight)
67
{
68
69
System.Drawing.Bitmap objPic, objNewPic;
70
try
71
{
72
objPic
=
new
System.Drawing.Bitmap(strOldPic);
73
objNewPic
=
new
System.Drawing.Bitmap(objPic, intWidth, intHeight);
74
objNewPic.Save(strNewPic);
75
76
}
77
catch
(Exception exp)
{
throw
exp; }
78
finally
79
{
80
objPic
=
null
;
81
objNewPic
=
null
;
82
}
83
}
84
85
public
void
SmallPic(
string
strOldPic,
string
strNewPic,
int
intWidth)
86
{
87
88
System.Drawing.Bitmap objPic, objNewPic;
89
try
90
{
91
objPic
=
new
System.Drawing.Bitmap(strOldPic);
92
int
intHeight
=
Convert.ToInt32(((intWidth
*
1.0
)
/
(objPic.Width
*
1.0
))
*
objPic.Height);
93
objNewPic
=
new
System.Drawing.Bitmap(objPic, intWidth, intHeight);
94
objNewPic.Save(strNewPic, objPic.RawFormat);
95
96
}
97
catch
(Exception exp)
{
throw
exp; }
98
finally
99
{
100
objPic
=
null
;
101
objNewPic
=
null
;
102
}
103
}
104
105
//
public void SmallPic(string strOldPic, string strNewPic, int intHeight)
106
//
{
107
108
//
System.Drawing.Bitmap objPic, objNewPic;
109
//
try
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 (Exception exp) { throw exp; }
118
//
finally
119
//
{
120
//
objPic = null;
121
//
objNewPic = null;
122
//
}
123
//
}
124
#endregion
125
126
}
127
}
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted on 2007-01-09 15:09
楚广明
阅读(1494)
评论(0)
编辑
收藏
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
最想要的Entity Framework功能
·
专访Jeffrey Richter:Windows 8是微软的重中之重
·
《福布斯》:谷歌进军硬件产品 难撼动苹果地位
·
美国空军拟最多购买1.8万台iPad 2
·
分析称专利之争让谷歌苹果两败俱伤
»
更多新闻...
最新知识库文章
:
·
高级编程语言的发展历程
·
如何学习一门新的编程语言?
·
学习不同编程语言的重要性
·
为什么我喜欢富于表达性的编程语言
·
计算机专业的女生为什么要学编程
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
导航
博客园
首页
新随笔
联系
订阅
管理
<
2007年1月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
公告
公告
个人简介
本名:楚广明
网名:chu888chu888
昵称:
楚广明
园龄:
5年2个月
荣誉:
推荐博客
粉丝:
115
关注:
3
搜索
最新随笔
1. 15 个微型的 JavaScript 框架
2. 8个神奇的网页动态流体布局及其做法揭秘
3. 缩略图在网页设计中应用的35个优秀案例
4. 视差滚动在网页设计中应用的21个优秀案例
5. 40+ 新鲜漂亮的大背景网站设计
随笔分类
(495)
.NET(11)
(rss)
Android(8)
(rss)
asp.netMVC(1)
(rss)
cms(1)
(rss)
css(45)
(rss)
html5(17)
(rss)
IOS(55)
(rss)
JavaScript面对对象(4)
(rss)
Jquery(94)
(rss)
json(4)
(rss)
linux(6)
(rss)
metro风格(3)
(rss)
Node.js(3)
(rss)
PHP(7)
(rss)
UED(6)
(rss)
webgl(4)
(rss)
WEB开发(83)
(rss)
WP7(1)
(rss)
开发工具(3)
(rss)
开源项目(1)
(rss)
人生随笔(32)
(rss)
数据库(5)
(rss)
算法(3)
(rss)
网站模板(44)
(rss)
系统管理(7)
(rss)
项目管理(9)
(rss)
移动WEB(1)
(rss)
音乐(2)
(rss)
游戏开发(4)
(rss)
资源分享(31)
(rss)
随笔档案
(571)
2012年2月 (66)
2012年1月 (124)
2011年12月 (161)
2011年11月 (75)
2011年10月 (15)
2011年9月 (38)
2011年8月 (1)
2011年5月 (7)
2011年1月 (3)
2010年12月 (1)
2010年11月 (1)
2010年8月 (3)
2010年7月 (7)
2010年6月 (3)
2010年5月 (2)
2010年1月 (1)
2009年9月 (1)
2009年7月 (2)
2009年5月 (1)
2009年4月 (2)
2009年3月 (4)
2009年1月 (1)
2008年12月 (4)
2008年11月 (6)
2008年10月 (3)
2008年9月 (1)
2008年8月 (3)
2008年7月 (12)
2008年6月 (9)
2008年5月 (1)
2008年4月 (1)
2008年3月 (1)
2008年2月 (2)
2007年12月 (1)
2007年4月 (1)
2007年3月 (1)
2007年2月 (2)
2007年1月 (2)
2006年12月 (2)
文章分类
(5)
C#编程(5)
(rss)
积分与排名
积分 - 255110
排名 - 295
阅读排行榜