ie421.NET

面对技术,你别无选择,.NET世界是如此精彩,而我们要做的就是:Thinking More

博客园 首页 新随笔 联系 订阅 管理
 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
posted on 2007-04-28 14:03  ie421  阅读(290)  评论(0编辑  收藏  举报