我想在文件位置的 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/