||
通过摄像头拍摄的图像与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;
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 15:23
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社