有点奇怪的问题,我不知道以前是否有人遇到过这个问题。
我们有一个 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;
}
}
关于asp.net - 为什么 Image.GetThumbnailImage 在 IIS6 和 IIS7.5 上的工作方式不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14261140/