在System.Web.Helpers.DLL中提供一个类:WebImage
通过她可以方便的进行图片处理,她提供了对图片的切割、翻转、旋转、加文字水印或图片水印等功能。
创建Asp.net mvc3网站项目。
在Controller中添加如下代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
private
static
readonly
string
ImagePath
=
@"
C:\Users\Administrator\Desktop\1.png
"
;
2
3 /// <summary>
4 /// 源图
5 /// </summary>
6 public void Origenal()
7 {
8 new WebImage(ImagePath)
9 .Write();
10 }
11
12 /// <summary>
13 /// 切割
14 /// </summary>
15 public void Cropping()
16 {
17 new WebImage(ImagePath)
18 .Crop( 10 , 30 , 50 , 100 )
19 .Write();
20 }
21
22 /// <summary>
23 /// 水平翻转
24 /// </summary>
25 public void HorizontalFilp()
26 {
27 new WebImage(ImagePath)
28 .FlipHorizontal()
29 .Write();
30 }
31
32 /// <summary>
33 /// 垂直翻转
34 /// </summary>
35 public void VerticalFilp()
36 {
37 new WebImage(ImagePath)
38 .FlipVertical()
39 .Write();
40 }
41
42 /// <summary>
43 /// 重置大小
44 /// </summary>
45 public void Resize()
46 {
47 new WebImage(ImagePath)
48 .Resize( 100 , 100 )
49 .Write();
50 }
51
52 /// <summary>
53 /// 左旋转
54 /// </summary>
55 public void RotateLeft()
56 {
57 new WebImage(ImagePath)
58 .RotateLeft()
59 .Write();
60 }
61
62 /// <summary>
63 /// 右旋转
64 /// </summary>
65 public void RotateRight()
66 {
67 new WebImage(ImagePath)
68 .RotateRight()
69 .Write();
70 }
71
72 /// <summary>
73 /// 文字水印
74 /// </summary>
75 public void TextWaterMark()
76 {
77 new WebImage(ImagePath)
78 .AddTextWatermark( " Xaoxong " , " Red " , 14 , " Bold " )
79 .Write();
80 }
81
82 /// <summary>
83 /// 图片水印
84 /// </summary>
85 public void ImageWaterMark()
86 {
87 var img = new WebImage(ImagePath)
88 .Resize( 100 , 100 );
89
90 new WebImage(ImagePath)
91 .AddImageWatermark(img)
92 .Write();
93 }
2
3 /// <summary>
4 /// 源图
5 /// </summary>
6 public void Origenal()
7 {
8 new WebImage(ImagePath)
9 .Write();
10 }
11
12 /// <summary>
13 /// 切割
14 /// </summary>
15 public void Cropping()
16 {
17 new WebImage(ImagePath)
18 .Crop( 10 , 30 , 50 , 100 )
19 .Write();
20 }
21
22 /// <summary>
23 /// 水平翻转
24 /// </summary>
25 public void HorizontalFilp()
26 {
27 new WebImage(ImagePath)
28 .FlipHorizontal()
29 .Write();
30 }
31
32 /// <summary>
33 /// 垂直翻转
34 /// </summary>
35 public void VerticalFilp()
36 {
37 new WebImage(ImagePath)
38 .FlipVertical()
39 .Write();
40 }
41
42 /// <summary>
43 /// 重置大小
44 /// </summary>
45 public void Resize()
46 {
47 new WebImage(ImagePath)
48 .Resize( 100 , 100 )
49 .Write();
50 }
51
52 /// <summary>
53 /// 左旋转
54 /// </summary>
55 public void RotateLeft()
56 {
57 new WebImage(ImagePath)
58 .RotateLeft()
59 .Write();
60 }
61
62 /// <summary>
63 /// 右旋转
64 /// </summary>
65 public void RotateRight()
66 {
67 new WebImage(ImagePath)
68 .RotateRight()
69 .Write();
70 }
71
72 /// <summary>
73 /// 文字水印
74 /// </summary>
75 public void TextWaterMark()
76 {
77 new WebImage(ImagePath)
78 .AddTextWatermark( " Xaoxong " , " Red " , 14 , " Bold " )
79 .Write();
80 }
81
82 /// <summary>
83 /// 图片水印
84 /// </summary>
85 public void ImageWaterMark()
86 {
87 var img = new WebImage(ImagePath)
88 .Resize( 100 , 100 );
89
90 new WebImage(ImagePath)
91 .AddImageWatermark(img)
92 .Write();
93 }