01.
<%@ Page Language=
"C#"
Debug=
"true"
%>
02.
<%@ Import Namespace=
"System.Drawing"
%>
03.
<%@ Import Namespace=
"System.Drawing.Imaging"
%>
04.
05.
<script runat=
"server"
>
06.
07.
void
Page_Load(
object
sender, EventArgs e)
08.
{
09.
int
intWidth = 0;
10.
int
intHeight = 0;
11.
string
FileName;
12.
string
NewFileName;
13.
14.
intWidth = 100;
15.
16.
intHeight = 0;
17.
18.
19.
20.
FileName =
"MyImages/Mygirl.jpg"
;
21.
NewFileName =
"MyImages/New_Mygirl.jpg"
;
22.
23.
24.
System.Drawing.Image objGraphic = System.Drawing.Image.FromFile(Server.MapPath(FileName));
25.
26.
Bitmap objBitmap;
27.
28.
if
(intHeight > 0) {
29.
objBitmap =
new
Bitmap(objGraphic, intWidth, intHeight);
30.
}
31.
else
{
32.
if
(objGraphic.Width > intWidth) {
33.
double
ratio = objGraphic.Height / objGraphic.Width;
34.
intHeight = (
int
)ratio * (
int
)intWidth;
35.
objBitmap =
new
Bitmap(objGraphic, intWidth, intHeight);
36.
}
37.
else
{
38.
objBitmap =
new
Bitmap(objGraphic);
39.
}
40.
}
41.
42.
43.
objBitmap.Save(Server.MapPath(NewFileName.ToString()), objGraphic.RawFormat);
44.
45.
46.
objGraphic.Dispose();
47.
48.
49.
objBitmap =
null
;
50.
objGraphic =
null
;
51.
52.
53.
this
.imgPicture.ImageUrl = NewFileName;
54.
55.
}
56.
57.
</script>
58.
<html>
59.
<head>
60.
<title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title>
61.
</head>
62.
<body>
63.
<form id=
"form1"
runat=
"server"
>
64.
<asp:Image id=
"imgPicture"
runat=
"server"
/>
65.
</form>
66.
</body>
67.
</html>
68.
</form>