加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

使用ASP.NET创建缩略图的“最佳”方法是什么?

发布时间:2020-12-16 00:20:58 所属栏目:asp.Net 来源:网络整理
导读:故事:用户上传将添加到照片库的图像.作为上传过程的一部分,我们需要A)将图像存储在Web服务器的硬盘上,B)将图像的缩略图存储在Web服务器的硬盘上. 这里的“最佳”定义为 相对容易实现,理解和维护 生成合理质量的缩略图 性能和高质量缩略图是次要的. 解决方法
故事:用户上传将添加到照片库的图像.作为上传过程的一部分,我们需要A)将图像存储在Web服务器的硬盘上,B)将图像的缩略图存储在Web服务器的硬盘上.

这里的“最佳”定义为

>相对容易实现,理解和维护
>生成合理质量的缩略图

性能和高质量缩略图是次要的.

解决方法

我想你最好的解决方案是使用.NET Image类中的 GetThumbnailImage .
// 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);
   }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读