我想调整一个图像到像thumb_image多个图像,Small_image,在ASP.NET C#点击一个按钮big_image。调整图片大小在ASP.NET C#
请为我提供帮助或对同一样品代码..
我想调整一个图像到像thumb_image多个图像,Small_image,在ASP.NET C#点击一个按钮big_image。调整图片大小在ASP.NET C#
请为我提供帮助或对同一样品代码..
你可以做这样的事情。
var thumbNail = CreateThumbnail(100, 100, fullPath);
public static Image CreateThumbnail(int maxWidth, int maxHeight, string path)
{
var image = Image.FromFile(path);
var ratioX = (double)maxWidth/image.Width;
var ratioY = (double)maxHeight/image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
image.Dispose();
return newImage;
}
System.Drawing中的所有对象必须设置有'using'条款,不能与.Dispose,因为这并不能保证他们的处置。 GC没有看到System.Drawing实例。 – 2013-05-30 15:04:36
我希望你使用一个库来做到这一点。这里有大量的代码示例,但他们不适合服务器端使用,而ImageResizer是。
至少read this article on what pitfalls to avoid if you decide to go copy & paste route。
你尝试过什么了吗? – 2013-02-22 06:38:53
如果你谷歌相同,你会得到可能的链接。你有没有尝试过其中之一? – 2013-02-22 06:43:43
是@Andrew理发我尝试之一,但它不工作 – user1986324 2013-02-22 07:16:58