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

5

6
Dim image,aNewImage As System.Drawing.Image7
dim width,height,newwidth,newheight as integer8
Dim callb As System.Drawing.Image.GetThumbnailImageAbort9

10

11
''生成缩略图12
image=System.Drawing.Image.FromFile(Server.MapPath("classpic/"+"rs1.jpg"))13
width=image.Width14
height=image.height15
if width>height then16
newwidth=11017
newheight=image.height/image.Width*newwidth18
else19
newheight=11020
newwidth=image.Width/image.height*newheight21
end if22

23

24
aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())25
aNewImage.Save(Server.MapPath("smallpic/"+"rs1.gif"))26
image.Dispose()27

28

29
End Sub30
</script>31

32



浙公网安备 33010602011771号