mafei863分享 http://blog.sciencenet.cn/u/mafei863 道法自然,道即合理

博文

c#-picturebox图像缩放后的保存

已有 7715 次阅读 2014-3-26 09:56 |个人分类:c#编程|系统分类:科研笔记

通过摄像头拍摄的图像与picturebox的尺寸不一致,则需要进行缩放对应保存。


/// <summary>

       /// 无论摄像头拍摄图像的大小,均以picturebox为标准进行缩小 、放大

       /// </summary>

       /// <param name="bmp"></param>

       /// <param name="pictureBox1"></param>

       /// <returns></returns>

       public Bitmap imgSuitablePicturebox(Bitmap bmp, System.Windows.Forms.PictureBox pictureBox1)

       {

           Bitmap tmpbmp = null;

           Rectangle oldrct = null, newrct = null;

           bmp = new Bitmap(pictureBox1.Image);            

           oldrct = new Rectangle(0, 0, bmp.Width, bmp.Height);

           tmpbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

           oldrct = new Rectangle(0, 0, bmp.Width, bmp.Height);

           Graphics g = Graphics.FromImage(tmpbmp);

           newrct = new Rectangle(0, 0, tmpbmp.Width, tmpbmp.Height);

           g.DrawImage(bmp, newrct, oldrct, GraphicsUnit.Pixel);

           g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

           g.Dispose();

           

           return tmpbmp;

       }




https://wap.sciencenet.cn/blog-538909-779273.html

上一篇:很多中国人从小就是喜欢抱怨别人
下一篇:如果在使用GetHdc方法后使用Graphics对象,请调用ReleaseHdc方法
收藏 IP: 125.46.3.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-22 05:52

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部