会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
circlesport
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
c# 添加图片水印,可以指定水印位置+生成缩略图
生成缩略图
1
2
/**/
///
<summary>
3
///
生成缩略图
4
///
</summary>
5
///
<param name="oldpath">
原图片地址
</param>
6
///
<param name="newpath">
新图片地址
</param>
7
///
<param name="tWidth">
缩略图的宽
</param>
8
///
<param name="tHeight">
缩略图的高
</param>
9
private
void
GreateMiniImage(
string
oldpath,
string
newpath,
int
tWidth,
int
tHeight)
10
{
11
12
try
13
{
14
15
System.Drawing.Image image
=
System.Drawing.Image.FromFile(oldpath);
16
double
bl
=
1d;
17
if
((image.Width
<=
image.Height)
&&
(tWidth
>=
tHeight))
18
{
19
bl
=
Convert.ToDouble(image.Height)
/
Convert.ToDouble(tHeight);
20
}
21
else
if
((image.Width
>
image.Height)
&&
(tWidth
<
tHeight))
22
{
23
bl
=
Convert.ToDouble(image.Width)
/
Convert.ToDouble(tWidth);
24
25
}
26
else
27
28
if
((image.Width
<=
image.Height)
&&
(tWidth
<=
tHeight))
29
{
30
if
(image.Height
/
tHeight
>=
image.Width
/
tWidth)
31
{
32
bl
=
Convert.ToDouble(image.Width)
/
Convert.ToDouble(tWidth);
33
34
}
35
else
36
{
37
bl
=
Convert.ToDouble(image.Height)
/
Convert.ToDouble(tHeight);
38
}
39
}
40
else
41
{
42
if
(image.Height
/
tHeight
>=
image.Width
/
tWidth)
43
{
44
bl
=
Convert.ToDouble(image.Height)
/
Convert.ToDouble(tHeight);
45
46
}
47
else
48
{
49
bl
=
Convert.ToDouble(image.Width)
/
Convert.ToDouble(tWidth);
50
51
}
52
53
}
54
55
56
Bitmap b
=
new
Bitmap(image ,Convert.ToInt32(image.Width
/
bl), Convert.ToInt32(image.Height
/
bl));
57
58
b.Save(newpath);
59
b.Dispose();
60
image.Dispose();
61
62
63
}
64
catch
65
{
66
67
68
}
69
70
}
posted on
2007-04-25 22:37
无极.net
阅读(
664
) 评论(
4
)
收藏
举报
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3