3、SWFUpload
下載地址:http://code.google.com/p/swfupload/
中文文檔幫助地址:http://www.phptogether.com/swfuploadoc/#uploadError
本文所使用的就是此插件,使用flash+jquery實現,可以更改按鈕及各種樣式;監聽事件也很全。
以下貼出源碼及設計思路,主要功能點包括:
1、圖片的上傳預覽(先將圖片上傳至服務器,然后再返回地址預覽,目前拋開html5比較靠譜的預覽方式)
2、縮略圖的產生(等比例縮放后再截取中間區域作為縮略圖,類似QQ空間的做法,不過貌似QQ空間加入了人臉識別的功能)
以下是此次實現的功能截圖:
1、Thumbnail.cs
代碼如下:
public class Thumbnial
{
/// <summary>
/// 生成縮略圖
/// </summary>
/// <param name="imgSource">原圖片</param>
/// <param name="newWidth">縮略圖寬度</param>
/// <param name="newHeight">縮略圖高度</param>
/// <param name="isCut">是否裁剪(以中心點)</param>
/// <returns></returns>
public static Image GetThumbnail(System.Drawing.Image imgSource, int newWidth, int newHeight, bool isCut)
{
int rWidth = 0; // 等比例縮放后的寬度
int rHeight = 0; // 等比例縮放后的高度
int sWidth = imgSource.Width; // 原圖片寬度
int sHeight = imgSource.Height; // 原圖片高度
double wScale = (double)sWidth / newWidth; // 寬比例
double hScale = (double)sHeight / newHeight; // 高比例
double scale = wScale < hScale ? wScale : hScale;
rWidth = (int)Math.Floor(sWidth / scale);
rHeight = (int)Math.Floor(sHeight / scale);
Bitmap thumbnail = new Bitmap(rWidth, rHeight);
try
{
// 如果是截取原圖,并且原圖比例小于所要截取的矩形框,那么保留原圖
新聞熱點
疑難解答