十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如下的内容段是关于C# 通过ASHX保存上传的图片并制作高质量的缩略图的内容,应该能对小伙伴也有帮助。
成都创新互联,为您提供网站建设、成都网站制作、网站营销推广、网站开发设计,对服务成都三轮搅拌车等多个行业拥有丰富的网站建设及推广经验。成都创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!
<%@ 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;
}
}
}
上传表单