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

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

C#圖片按比例縮放

2019-11-14 16:52:52
字體:
來源:轉載
供稿:網友

C#圖片按比例縮放:

 1       // 按比例縮放圖片 2         public Image ZoomPicture(Image SourceImage, int TargetWidth, int TargetHeight) 3         { 4             int IntWidth; //新的圖片寬 5             int IntHeight; //新的圖片高 6             try 7             { 8                 System.Drawing.Imaging.ImageFormat format = SourceImage.RawFormat; 9                 System.Drawing.Bitmap SaveImage = new System.Drawing.Bitmap(TargetWidth, TargetHeight);10                 Graphics g = Graphics.FromImage(SaveImage);11                 g.Clear(Color.White);12 13                 //計算縮放圖片的大小 http://m.survivalescaperooms.com/roucheng/14 15                 if (SourceImage.Width > TargetWidth && SourceImage.Height <= TargetHeight)//寬度比目的圖片寬度大,長度比目的圖片長度小16                 {17                     IntWidth = TargetWidth;18                     IntHeight = (IntWidth * SourceImage.Height) / SourceImage.Width;19                 }20                 else if (SourceImage.Width <= TargetWidth && SourceImage.Height > TargetHeight)//寬度比目的圖片寬度小,長度比目的圖片長度大21                 {22                     IntHeight = TargetHeight;23                     IntWidth = (IntHeight * SourceImage.Width) / SourceImage.Height;24                 }25                 else if (SourceImage.Width <= TargetWidth && SourceImage.Height <= TargetHeight) //長寬比目的圖片長寬都小26                 {27                     IntHeight = SourceImage.Width;28                     IntWidth = SourceImage.Height;29                 }30                 else//長寬比目的圖片的長寬都大31                 {32                     IntWidth = TargetWidth;33                     IntHeight = (IntWidth * SourceImage.Height) / SourceImage.Width;34                     if (IntHeight > TargetHeight)//重新計算35                     {36                         IntHeight = TargetHeight;37                         IntWidth = (IntHeight * SourceImage.Width) / SourceImage.Height;38                     }39                 }40 41                 g.DrawImage(SourceImage, (TargetWidth - IntWidth) / 2, (TargetHeight - IntHeight) / 2, IntWidth, IntHeight);42                 SourceImage.Dispose();43 44                 return SaveImage;45             }46             catch (Exception ex)47             {48               49             }50 51             return null;52         }

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁国市| 苏尼特左旗| 铜川市| 遂溪县| 饶平县| 苗栗市| 凤冈县| 遂溪县| 泰兴市| 海盐县| 大悟县| 新闻| 铜山县| 新泰市| 金秀| 喀喇沁旗| 朝阳区| 偃师市| 仁寿县| 东阿县| 宝坻区| 屯留县| 七台河市| 南充市| 五台县| 大悟县| 景宁| 客服| 黄梅县| 清新县| 扎兰屯市| 朝阳县| 姚安县| 井冈山市| 大田县| 都兰县| 浑源县| 兰州市| 昌黎县| 平凉市| 乌恰县|