1当我们要上传图片的时候,往往需要生成缩略图,以往我们要使用第三方控件才能完成。在asp.net中用下面方法轻松搞定
2<script language="VB" runat="server">
3Sub Page_Load(sender As Object, e As EventArgs)
4
5
6Dim image,aNewImage As System.Drawing.Image
7dim width,height,newwidth,newheight as integer
8Dim callb As System.Drawing.Image.GetThumbnailImageAbort
9
10
11''生成缩略图
12image=System.Drawing.Image.FromFile(Server.MapPath("classpic/"+"rs1.jpg"))
13width=image.Width
14height=image.height
15if width>height then
16newwidth=110
17newheight=image.height/image.Width*newwidth
18else
19newheight=110
20newwidth=image.Width/image.height*newheight
21end if
22
23
24aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
25aNewImage.Save(Server.MapPath("smallpic/"+"rs1.gif"))
26image.Dispose()
27
28
29End Sub
30</script>
31
32
2<script language="VB" runat="server">
3Sub Page_Load(sender As Object, e As EventArgs)
4
5
6Dim image,aNewImage As System.Drawing.Image
7dim width,height,newwidth,newheight as integer
8Dim callb As System.Drawing.Image.GetThumbnailImageAbort
9
10
11''生成缩略图
12image=System.Drawing.Image.FromFile(Server.MapPath("classpic/"+"rs1.jpg"))
13width=image.Width
14height=image.height
15if width>height then
16newwidth=110
17newheight=image.height/image.Width*newwidth
18else
19newheight=110
20newwidth=image.Width/image.height*newheight
21end if
22
23
24aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
25aNewImage.Save(Server.MapPath("smallpic/"+"rs1.gif"))
26image.Dispose()
27
28
29End Sub
30</script>
31
32