如何高效地扩展和裁剪图像在ASP.NET应用程序? [英] How to efficiently scale and crop images in an ASP.NET app?
问题描述
我们遇到与一个ASP.NET应用程序,允许用户上传和裁剪图像的问题。图像都调整为固定尺寸之后。我们基本用完时,一个大的文件处理内存;似乎JPEG的处理是相当低效 - 我们使用System.Drawing.BitMap。你有任何一般性的建议,也许有些指向一个更高效的图像处理库?你有什么经验?
We're having problems with an ASP.NET application which allows users to upload, and crop images. The images are all scaled to fixed sizes afterwards. We basically run out of memory when a large file is processed; it seems that the handling of JPEG is rather inefficient -- we're using System.Drawing.BitMap. Do you have any general advice, and perhaps some pointers to a more efficient image handling library? What experiences do you have?
推荐答案
我有同样的问题,解决的办法是使用System.Drawing.Graphics尽快做转换和处理每一个位图对象,因为我是用它完成。下面是从我的图书馆(调整)的例子:
I had the same problem, the solution was to use System.Drawing.Graphics to do the transformations and dispose every bitmap object as soon as I was finished with it. Here's a sample from my library (resizing) :
public Bitmap ApplyTo(Bitmap bitmap)
{
using (bitmap)
{
Bitmap newBitmap = new Bitmap(bitmap, CalculateNewSize(bitmap));
using (Graphics graphics = Graphics.FromImage(newBitmap))
{
graphics.SmoothingMode =
SmoothingMode.None;
graphics.InterpolationMode =
InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality =
CompositingQuality.HighQuality;
graphics.DrawImage(
bitmap,
new Rectangle(0, 0, newBitmap.Width, newBitmap.Height));
}
return newBitmap;
}
}
这篇关于如何高效地扩展和裁剪图像在ASP.NET应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!