|
|
|
ขอ form การ compression image Jpeg หน่อยครับ ขอ form การ compression image Jpeg หน่อยครับ |
|
|
|
|
|
|
|
ลองใช้การ Resize ด้วย C# น่ะครับ
Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
int intWidth = 0;
int intHeight = 0;
string FileName;
string NewFileName;
intWidth = 100;
//*** Fix Width ***//
intHeight = 0;
//*** If = 0 Auto Re-Cal Size ***//
FileName = "MyImages/Mygirl.jpg";
NewFileName = "MyImages/New_Mygirl.jpg";
System.Drawing.Image objGraphic = System.Drawing.Image.FromFile(Server.MapPath(FileName));
Bitmap objBitmap;
//*** Calculate Height ***//
if (intHeight > 0) {
objBitmap = new Bitmap(objGraphic, intWidth, intHeight);
}
else {
if (objGraphic.Width > intWidth) {
double ratio = objGraphic.Height / objGraphic.Width;
intHeight = (int)ratio * (int)intWidth;
objBitmap = new Bitmap(objGraphic, intWidth, intHeight);
}
else {
objBitmap = new Bitmap(objGraphic);
}
}
//*** Save As ***//
objBitmap.Save(Server.MapPath(NewFileName.ToString()), objGraphic.RawFormat);
//*** Close ***//
objGraphic.Dispose();
//*** Nothing ***//
objBitmap = null;
objGraphic = null;
//*** View Images ***//
this.imgPicture.ImageUrl = NewFileName;
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Image id="imgPicture" runat="server" />
</form>
</body>
</html>
</form>
|
|
|
|
|
Date :
2009-10-29 06:51:31 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|