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