




















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
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。