什么是"最佳"方法来创建使用ASP.NET的缩略图? [英] What is the "best" way to create a thumbnail using ASP.NET?
本文介绍了什么是"最佳"方法来创建使用ASP.NET的缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
故事:用户上载将被添加到一个图片库的图像。由于上传过程的一部分,我们需要A)将图像存储在Web服务器的硬盘驱动器和B)存储在Web服务器的硬盘驱动器上的图像的缩略图。
Story: The user uploads an image that will be added to a photo gallery. As part of the upload process, we need to A) store the image on the web server's hard drive and B) store a thumbnail of the image on the web server's hard drive.
最佳在这里被定义为
- 比较容易实现,理解和维护
- 结果的合理的质量缩略图
性能和高品质的缩略图都是次要的。
Performance and high-quality thumbnails are secondary.
推荐答案
我想你最好的解决办法是使用GetThumbnailImage 从.NET 图片类。
I suppose your best solution would be using the GetThumbnailImage from the .NET Image class.
// Example in C#, should be quite alike in ASP.NET
// Assuming filename as the uploaded file
using ( Image bigImage = new Bitmap( filename ) )
{
// Algorithm simplified for purpose of example.
int height = bigImage.Height / 10;
int width = bigImage.Width / 10;
// Now create a thumbnail
using ( Image smallImage = image.GetThumbnailImage( width,
height,
new Image.GetThumbnailImageAbort(Abort), IntPtr.Zero) )
{
smallImage.Save("thumbnail.jpg", ImageFormat.Jpeg);
}
}
这篇关于什么是"最佳"方法来创建使用ASP.NET的缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文