c# - 创建缩略图

标签 c# asp.net gridview thumbnails

我想在文件位置的 GridView 中显示缩略图。如何生成.jpeg文件? 我在 asp.net 中使用 C# 语言。

最佳答案

您必须在 Image 类中使用 GetThumbnailImage 方法:

https://msdn.microsoft.com/en-us/library/8t23aykb%28v=vs.110%29.aspx

这是一个粗略的示例,它获取一个图像文件并从中制作缩略图,然后将其保存回磁盘。

Image image = Image.FromFile(fileName);
Image thumb = image.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(fileName, "thumb"));

它位于 System.Drawing 命名空间中(在 System.Drawing.dll 中)。

行为:

If the Image contains an embedded thumbnail image, this method retrieves the embedded thumbnail and scales it to the requested size. If the Image does not contain an embedded thumbnail image, this method creates a thumbnail image by scaling the main image.


重要:上面 Microsoft 链接的备注部分警告某些潜在问题:

The GetThumbnailImage method works well when the requested thumbnail image has a size of about 120 x 120 pixels. If you request a large thumbnail image (for example, 300 x 300) from an Image that has an embedded thumbnail, there could be a noticeable loss of quality in the thumbnail image.

It might be better to scale the main image (instead of scaling the embedded thumbnail) by calling the DrawImage method.

关于c# - 创建缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2808887/

相关文章:

javascript - 使用 jquery 从 asp 列表框中获取所选项目的数量

c# - 如何在单击 gridview 行时调用函数。这两个函数都放在 aspx 页面的脚本标签中

c# - OnCollisionEnter 函数如何工作 "Fundamentally"?

c# - Debug.Assert 和 Debug.Fail 是否应该自由使用,是否应该留在生产代码中?

c# - 将数组列表转换为字符串

android - GridView 的滚动偏移量

asp.net - 如何将行跨度添加到 GridView 中的第一列?

c# - 使用 edmgen 生成实体类

c# - 查明应用程序是否需要管理员权限

asp.net - 如何在母版页上放置两次占位符?