01.
<%@ Page Language=
"VB"
%>
02.
<%@ Import
Namespace
=
"System.Drawing"
%>
03.
<%@ Import
Namespace
=
"System.Drawing.Imaging"
%>
04.
05.
<script runat=
"server"
>
06.
07.
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
08.
Dim
intWidth,intHeight
As
Integer
09.
Dim
FileName,NewFileName
As
String
10.
11.
intWidth = 100
12.
intHeight = 0
13.
14.
15.
FileName =
"MyImages/Mygirl.jpg"
16.
NewFileName =
"MyImages/New_Mygirl.jpg"
17.
18.
19.
Dim
objGraphic
As
System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(FileName))
20.
21.
Dim
objBitmap
As
Bitmap
22.
23.
If
intHeight > 0
Then
24.
objBitmap =
New
Bitmap(objGraphic, intWidth, intHeight)
25.
Else
26.
If
objGraphic.Width > intWidth
Then
27.
Dim
ratio
As
Double
= objGraphic.Height / objGraphic.Width
28.
intHeight = ratio * intWidth
29.
objBitmap =
New
Bitmap(objGraphic, intWidth, intHeight)
30.
Else
31.
objBitmap =
New
Bitmap(objGraphic)
32.
End
If
33.
End
If
34.
35.
36.
objBitmap.Save(Server.MapPath(NewFileName), objGraphic.RawFormat)
37.
38.
39.
objGraphic.Dispose()
40.
41.
42.
objBitmap =
Nothing
43.
objGraphic =
Nothing
44.
45.
46.
Me
.imgPicture.ImageURL = NewFileName
47.
48.
End
Sub
49.
50.
</script>
51.
<html>
52.
<head>
53.
<title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title>
54.
</head>
55.
<body>
56.
<form id=
"form1"
runat=
"server"
>
57.
<asp:Image id=
"imgPicture"
runat=
"server"
/>
58.
</form>
59.
</body>
60.
</html>
61.
</form>