發(fā)文章
發(fā)文工具
撰寫
網(wǎng)文摘手
文檔
視頻
思維導(dǎo)圖
隨筆
相冊
原創(chuàng)同步助手
其他工具
圖片轉(zhuǎn)文字
文件清理
AI助手
留言交流
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://www.cnblogs.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 }
來自: 昵稱10504424 > 《工作》
0條評論
發(fā)表
請遵守用戶 評論公約
Word批量設(shè)置圖片大小,按比例縮放
Word批量設(shè)置圖片大小,按比例縮放。
Excel如何批量將圖片按比例擴大?
Excel如何批量將圖片按比例擴大?今天跟大家分享一下Excel怎么批量導(dǎo)入指定名稱產(chǎn)品圖片?1.打開Excel表格,如下圖想要將表格中的圖片擴...
按比例的變換
按比例的變換。
ID圖片如何按比例在形狀中顯示?
ID圖片如何按比例在形狀中顯示?這個操作非常簡單,下面就來看小編的操作方法吧。1.當(dāng)前我們將圖片置入矩形框中發(fā)現(xiàn)圖片過大。2.這個時...
跟我學(xué)用 PCStitch 7自制編織圖案
除了用針縫圖案以外,很多時候也有喜歡帶線同時編織配色圖案的,這時使用等比例繪制的編織圖會有以下兩種情況讓操作出現(xiàn)不方便。1、每一...
android:scaleType屬性
android:scaleType屬性。android:scaleType是控制圖片如何resized/moved來匹對ImageView的size。ScaleType / android:scaleType值的意義區(qū)別:CENTER /center 按圖片的原來size居中顯示,當(dāng)圖片長/寬...
ImageView.ScaleType屬性值
(1)當(dāng)圖片大于ImageView的寬高:以圖片的中心點和ImageView的中心點為基準,按比例縮小圖片,直到圖片的寬高有一邊等于ImageView的寬高,則對于另一邊,圖片的長度大于或等于ImageView的長度,最后用Im...
[Android] ImageView.ScaleType設(shè)置圖解
ScaleType設(shè)置圖解。[Android] ImageView.ImageView的Scaletype決定了圖片在View上顯示時的樣子,如進行何種比例的縮放,及顯示圖片的整...
使圖片按比例縮放應(yīng)選用
使圖片按比例縮放應(yīng)選用。在WORD文檔中,在菜單欄上新增視圖“圖片格式”下方的圖片大小設(shè)置界面,設(shè)置圖片按比列縮放,具體操作如下:...
微信掃碼,在手機上查看選中內(nèi)容