【发布时间】:2010-08-20 10:11:09
【问题描述】:
我正在从数据库加载图像,并希望根据某些输入动态调整它们的大小。
代码是这样的:
public ActionResult GetImage(string imageID, int? width, int? height, bool constrain)
{
ValidateImageInput(width, height, constrain);
ImageWithMimeType info = LoadFromDatabase(imageID);
if(info == null)
throw new HttpException(404, "Image with that name or id was not found.");
Resize(info.Bytedata, width, height, constrain, info.MimeType);
return File(info.Data, info.MimeType);
}
如何以保留编码类型等的方式实现 Resize?我查看了Image resizing efficiency in C# and .NET 3.5,但看不到它会如何保留编码 - 因为创建新的位图肯定不会被编码?
【问题讨论】:
-
标题建议您要保留 mimetype,但问题本身涉及编码类型(我假设是文件格式)。你想保留什么?
-
在下面查看我的答案。编码是指编解码器格式。
标签: c# asp.net-mvc-2 image-processing resize