标签:
#region -生成缩略图- /// <summary> /// 生成缩略图 /// </summary> /// <param name="orginalImagePath">原图片对象</param> /// <param name="thumbnailPath">缩略图的路径</param> /// <param name="width">指定宽度</param> /// <param name="heigth">指定高度</param> /// <param name="model">缩放类型 HW:可以变形 W:指定宽度,高安比例缩放 "H"://指定高度,宽安比例绽放 "Cut"://指定高宽,裁减(不变形)</param> public static void MakeThumbnail(Image orginalPric, string thumbnailPath, int width, int heigth, string model) { Image originalImage = orginalPric;//获得图片对象 int towidth = width; int toheigth = heigth; int x = 0; int y = 0; int ow = originalImage.Width; int oh = originalImage.Height; #region -缩略图的类型- switch (model) { case "HW"://指定高宽缩放(可以变形) break; case "W"://指定宽度,高安比例缩放 toheigth = originalImage.Height * width / originalImage.Width; break; case "H"://指定高度,宽安比例绽放 towidth = originalImage.Width * heigth / originalImage.Height; break; case "Cut"://指定高宽,裁减(不变形) if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheigth) { oh = originalImage.Height; ow = originalImage.Height * towidth / toheigth; y = 0; x = (originalImage.Width - ow) / 2; } else { ow = originalImage.Width; oh = originalImage.Width * towidth / towidth; y = 0; x = (originalImage.Height - oh) / 2; } break; default: break; } #endregion
标签:
原文地址:http://www.cnblogs.com/LikeNeng/p/4215580.html