国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

淺談圖片上傳之剪切

2019-11-17 02:41:36
字體:
來源:轉載
供稿:網友

淺談圖片上傳之剪切

對于一個網站來說,圖片顯示都是有一定的寬高比的,而客戶上傳的圖片大多未經過剪切,故上傳以后對圖片進行一定的剪切是非常必要的。

如此,我們應當剪一個類來完成這項工作。

 public class ImageHelper{///圖片寬高比,默認1.333 double _webWidth=1.333;/// <summary>///網站顯示圖片的 寬/高比/// </summary>public double WebWidth{get { return _webWidth; }set {_webWidth = value; }}/// <summary>/// 根據寬高比剪切圖片,_webWidth/// </summary>/// <param name="img">需要剪切的圖片</param>/// <returns></returns>public Bitmap CutImage(Bitmap img){int width = img.Width;int height = img.Height;Rectangle section = new Rectangle();//假如寬帶高于高度圖片if (width >= height){//根據網站寬高比例計算出寬度section.Width = (int)(height * _webWidth);//剪切寬大于原寬,取原寬if (section.Width > width)section.Width = width;section.Height = height;section.Y = 0;//計算出開始截圖的X定位,計算方式為(原寬-剪切寬/2)section.X = (int)((width - section.Width) / 2);}///假如高度大于寬度的圖片if (width < height){//根據寬高比計算出高度,為寬度/寬高比section.Height = (int)(width / _webWidth);//剪切寬大于原高,取原高if (section.Height > height)section.Height = height;section.Width = width;section.X = 0;//計算出開始截圖的Y定位,計算方式為(原高-剪切高/2)section.Y = (int)((height - section.Height) / 2);}Bitmap pickedImage = new Bitmap(section.Width, section.Height);Graphics pickedG = Graphics.FromImage(pickedImage);//開始剪切并填充pickedG.DrawImage(img, new Rectangle(0, 0, section.Width, section.Height), section,GraphicsUnit.Pixel); return pickedImage;}}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 班戈县| 伊吾县| 利津县| 镇宁| 恩平市| 姜堰市| 襄垣县| 靖西县| 禄丰县| 镇巴县| 淳安县| 大余县| 偃师市| 洛浦县| 封丘县| 涞水县| 巧家县| 西峡县| 监利县| 英吉沙县| 新晃| 奉节县| 新平| 五大连池市| 五莲县| 潮州市| 沙湾县| 兴安盟| 阜城县| 澎湖县| 绵竹市| 黄浦区| 石泉县| 常州市| 同德县| 长宁区| 阿城市| 龙口市| 张家港市| 霍山县| 灵宝市|