任何人都知道ASP.net的任何好的Image resize API?
答案 0 :(得分:2)
答案 1 :(得分:2)
ImageResizer库正在积极开发,维护和支持(自2007年起)。它是最新的性能技术,功能,并具有简单的API。它安全,可靠,可为数百个商业网站提供支持。
它与ASP.NET 2.0到4.0,MVC兼容,并且在IIS 7中设计得非常快。
答案 2 :(得分:1)
以下是我使用的内容:
internal static System.Drawing.Image FixedSize(System.Drawing.Image imgPhoto, int Width, int Height)
{
int sourceWidth = Convert.ToInt32(imgPhoto.Width);
int sourceHeight = Convert.ToInt32(imgPhoto.Height);
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width -
(sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height -
(sourceHeight * nPercent)) / 2);
}
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(Width, Height,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.Clear(Color.Black);
grPhoto.InterpolationMode =
InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
用法非常简单:
System.Drawing.Image orignalImage = Image.FromFile(filePath);
System.Drawing.Image resizedImage = FixedSize(originalImage, 640, 480);
答案 3 :(得分:0)
调整图像大小很简单,不需要API。我为这项任务写了自己的。如果代码可以让你走上这条道路,那么这里有点。
// get original image
System.Drawing.Image orignalImage = Image.FromFile(originalPath);
// create a new image at the desired size
System.Drawing.Bitmap newImage = new Bitmap(450, 338);
// create grpahics object to draw with
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImage);
//draw the new image
g.DrawImage(orignalImage, r);
// save the new image
newImage.Save(System.IO.Path.Combine(OUTPUT_FOLDER_PATH , ImageName.Replace(" ", "")));
答案 4 :(得分:0)
我将提供此作为其他答案的替代方案。 Image Magick是一个非常强大和成熟的图像处理库,您可以在.net中使用它。我用它取得了很大的成功。
答案 5 :(得分:0)