发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
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条评论
发表
请遵守用户 评论公约
Word批量设置图片大小,按比例缩放
Word批量设置图片大小,按比例缩放。
Excel如何批量将图片按比例扩大?
Excel如何批量将图片按比例扩大?今天跟大家分享一下Excel怎么批量导入指定名称产品图片?1.打开Excel表格,如下图想要将表格中的图片扩...
按比例的变换
按比例的变换。
ID图片如何按比例在形状中显示?
ID图片如何按比例在形状中显示?这个操作非常简单,下面就来看小编的操作方法吧。1.当前我们将图片置入矩形框中发现图片过大。2.这个时...
跟我学用 PCStitch 7自制编织图案
除了用针缝图案以外,很多时候也有喜欢带线同时编织配色图案的,这时使用等比例绘制的编织图会有以下两种情况让操作出现不方便。1、每一...
android:scaleType属性
android:scaleType属性。android:scaleType是控制图片如何resized/moved来匹对ImageView的size。ScaleType / android:scaleType值的意义区别:CENTER /center 按图片的原来size居中显示,当图片长/宽...
ImageView.ScaleType属性值
(1)当图片大于ImageView的宽高:以图片的中心点和ImageView的中心点为基准,按比例缩小图片,直到图片的宽高有一边等于ImageView的宽高,则对于另一边,图片的长度大于或等于ImageView的长度,最后用Im...
[Android] ImageView.ScaleType设置图解
ScaleType设置图解。[Android] ImageView.ImageView的Scaletype决定了图片在View上显示时的样子,如进行何种比例的缩放,及显示图片的整...
使图片按比例缩放应选用
使图片按比例缩放应选用。在WORD文档中,在菜单栏上新增视图“图片格式”下方的图片大小设置界面,设置图片按比列缩放,具体操作如下:...
微信扫码,在手机上查看选中内容