这是一个奇怪的问题,我不知道以前是否有人遇到过这个问题。
我们有一个ASP.net页面在文件系统上生成物理缩略图jpeg文件,并将完整大小的图像复制到不同的位置。因此,我们输入一张图像,在一个位置得到完整的副本,在另一个位置得到102*68的小图像。
我们目前正在考虑最终从Server 2003上的IIS6迁移到Server 2008R2上的IIS7.5,除非有一个问题。
在旧系统上(所以IIS6/Server 2003),黑色边框被删除,图像保持在正确的比例。在新系统(IIS7.5/Server 2008)中,缩略图与JPEG中的缩略图完全相同,带有黑色边框,但这使得缩略图稍微被压扁,显然包含难看的黑色边框。
有人知道为什么会发生这种情况吗?我在谷歌上搜索了一下,似乎找不到哪种行为是"正确的"。我的直觉告诉我,新系统正确地呈现了缩略图,但我不知道。
谁有什么建议来解决这个问题?我认为这是。net的差异。不是IIS。
只要重写你的代码,你就可以节省很多时间,非常简单的事情。
这是一个图像处理程序,我写了一会儿,重新绘制任何图像到您的设置
public class image_handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// set file
string ImageToDraw = context.Request.QueryString["FilePath"];
ImageToDraw = context.Server.MapPath(ImageToDraw);
// Grab images to work on's true width and height
Image ImageFromFile = Image.FromFile(ImageToDraw);
double ImageFromFileWidth = ImageFromFile.Width;
double ImageFromFileHeight = ImageFromFile.Height;
ImageFromFile.Dispose();
// Get required width and work out new dimensions
double NewHeightRequired = 230;
if (context.Request.QueryString["imageHeight"] != null)
NewHeightRequired = Convert.ToDouble(context.Request.QueryString["imageHeight"]);
double DivTotal = (ImageFromFileHeight / NewHeightRequired);
double NewWidthValue = (ImageFromFileWidth / DivTotal);
double NewHeightVale = (ImageFromFileHeight / DivTotal);
NewWidthValue = ImageFromFileWidth / (ImageFromFileWidth / NewWidthValue);
NewHeightVale = ImageFromFileHeight / (ImageFromFileHeight / NewHeightVale);
// Set new width, height
int x = Convert.ToInt16(NewWidthValue);
int y = Convert.ToInt16(NewHeightVale);
Bitmap image = new Bitmap(x, y);
Graphics g = Graphics.FromImage(image);
Image thumbnail = Image.FromFile(ImageToDraw);
// Quality Control
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawImage(thumbnail, 0, 0, x, y);
g.Dispose();
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
image.Dispose();
}
public bool IsReusable
{
get
{
return true;
}
}