---
title: "缩略图"
author: "流星剑"
date: "2011-05-16T11:19:48Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-05-16T11:19:48Z"
id: 1045331
url: "https://jaylong.iteye.com/blog/1045331"
---

**缩略图**

Web应用中最薄弱的环节就是传输，即速度问题。图片格式的数据往往比较大，所以网络中并不适合传输较大的图片。除了采用压缩格式（比如GIF,JPEG等）传输外，还可以使用缩略图的方式加快浏览速度，也可以节省页面空间。使用Image类中的GetThumbnailImage方法可以很方便地生成缩略图，如下面的代码示例：

```
  private bool ThumbnailCallback()
    {
        // 取消操作回调 
        return false;
    }
    // 产生缩略图
    private void Thumb(string imgPath, string thumbPath)
    {
        System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
        System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath); // 通过文件构造
        //生成缩略图
        System.Drawing.Image myThumbnail = img.GetThumbnailImage(100, 50, myCallback, IntPtr.Zero);
        myThumbnail.Save(thumbPath); // 保存缩略图
    }
```

 

```
Thumb(Server.MapPath("~/th.jpg"), Server.MapPath("~/tht_small.jpg"));
```