如下的內容段是關于C# 通過ASHX保存上傳的圖片并制作高質量的縮略圖的內容,應該能對小伙伴也有幫助。
成都創(chuàng)新互聯(lián),為您提供網(wǎng)站建設、成都網(wǎng)站制作、網(wǎng)站營銷推廣、網(wǎng)站開發(fā)設計,對服務成都三輪攪拌車等多個行業(yè)擁有豐富的網(wǎng)站建設及推廣經驗。成都創(chuàng)新互聯(lián)網(wǎng)站建設公司成立于2013年,提供專業(yè)網(wǎng)站制作報價服務,我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進步,是我們永遠的責任!
<%@ WebHandler Language="C#" Class="UploadFile" Debug="true" %>
using System;
using System.Web;
public class UploadFile : IHttpHandler
{
public void Proce***equest(HttpContext context)
{
context.Response.ContentType = "text/plain";
HttpPostedFile f1 = context.Request.Files["f1"];
String fileExt = System.IO.Path.GetExtension(f1.FileName);
System.Drawing.Image image = System.Drawing.Image.FromStream(f1.InputStream);
int newWidth = 300, newHeight = 200;
if ((decimal)image.Width / image.Height > (decimal)newWidth / newHeight)
{
}
else if ((decimal)image.Width / image.Height < (decimal)newWidth / newHeight)
{
}
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, newWidth, newHeight);
g.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
bmp.Save(context.Server.MapPath("~/") + DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt);
bmp.Dispose();
image.Dispose();
context.Response.Write("OK");
}
public bool IsReusable
{
get
{
return false;
}
}
}
上傳表單