06 Sep 2010
Support Center
»
Knowledgebase
»
How do I generate thumbnail in ASP.NET script? 我如何使用ASP.NET程式製作縮圖?
How do I generate thumbnail in ASP.NET script? 我如何使用ASP.NET程式製作縮圖?
Solution
You could generate thumbnail for your image in ASP.NET script, below is the sample code:
你可以在ASP.NET script中為你的圖片製作縮圖, 以下是參考程式碼:
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script Language="C#" runat="server">
protected Size ThumbNailSize = new Size(40,20);
private void Page_Load(object sender, System.EventArgs e)
{
string sPhysicalPath = Server.MapPath(".");
string sFileName = "test.jpg";
string sThumbName = "thumb_test.jpg";
this.GenerateThumbNail(sPhysicalPath,sFileName,sThumbName,ImageFormat.Jpeg);
}
public void GenerateThumbNail(string sPhysicalPath,string sOrgFileName, string sThumbNailFileName,ImageFormat oFormat)
{
try
{
System.Drawing.Image oImg = System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);
System.Drawing.Image oThumbNail = new Bitmap(this.ThumbNailSize.Width, this.ThumbNailSize.Height, oImg.PixelFormat);
Graphics oGraphic = Graphics.FromImage(oThumbNail);
oGraphic.CompositingQuality = CompositingQuality.HighQuality ;
oGraphic.SmoothingMode = SmoothingMode.HighQuality ;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic ;
Rectangle oRectangle = new Rectangle(0, 0, this.ThumbNailSize.Width, this.ThumbNailSize.Height);
oGraphic.DrawImage(oImg, oRectangle);
oThumbNail.Save(sPhysicalPath + @"\" + sThumbNailFileName,oFormat);
oImg.Dispose();
}
catch (Exception) { }
}
</script>
Article Details
Article ID:
40
Created On:
03 Feb 2010 11:24 PM
This answer was helpful
This answer was not helpful
Back
Login
[Lost Password]
Email:
Password:
Remember Me:
Search
-- Entire Support Site --
Knowledgebase
Downloads
Article Options
Print Article
PDF Version
Email Article
Add to Favorites
Home
|
Register
|
Submit a Ticket
|
Knowledgebase
|
Downloads
Language:
English (U.S.)
繁體中文
简体中文
Help Desk Software By Kayako eSupport v3.60.04