如何创建缩略图? [英] How Do I Create Thumbnails?

查看:70
本文介绍了如何创建缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个图像文件夹,现在我需要有一个第二个文件夹,我将图像存储为缩略图,以便它们以小尺寸显示。如何将它们保存在该文件夹中?

I have a folder of images in my project now i need to have a second folder where i will store images as thumbnails so that they appear in small sizes. How can i save them in that folder?

推荐答案

我将创建一个名为Thumbs的子目录,并将拇指图像存储在与其完全相同的名称下。完整的图像。

然后我使用这段代码:

I'd create a subdirectory called "Thumbs" and store the thumb image in that under exactly the same name as the full image.
Then I use this code:
/// <summary>
/// Create a thumbnail image.
/// </summary>
/// <param name="path">path to full size image</param>
/// <param name="width">Width of thumbnail</param>
/// <param name="height">Height of thumbnail</param>
public static Image GetThumbnailImage(string path, int width, int height)
    {
    using (Image image = Image.FromFile(path))
        {
        Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
        return image.GetThumbnailImage(width, height, myCallback, IntPtr.Zero);
        }
    }
/// <summary>
/// This is not used in GDI+ 1.0, but must be supplied to some GDI calls.
/// E.g. Image.GetThumbnailImage
/// </summary>
/// <returns>false always</returns>
private static bool ThumbnailCallback()
    {
    return false;
    }



您只需要调用Image.Save来保存缩略图。


All you need then is to call Image.Save to save the thumbnail.


http://www.aspdotnet-suresh.com/2011/ 05 / how-to-create-or-generate-thumbnails.html [ ^ ]


这篇关于如何创建缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆