C# 使用DirectShow更改图像捕获的尺寸

C# 使用DirectShow更改图像捕获的尺寸,c#,.net,image-processing,video-capture,C#,.net,Image Processing,Video Capture,我正在使用DirecShowLib-2005.Dll从笔记本电脑网络摄像头拍摄照片。最初我使用的图像大小为640 x 840。这些配置在我现在使用的示例中给出 const int VIDEODEVICE = 0; const int VIDEOWIDTH = 640; const int VIDEOHEIGHT = 480; const int VIDEOBITSPERPIXEL = 24; 在声明捕获对象时传递这些值,即 cam = new Capture(V

我正在使用DirecShowLib-2005.Dll从笔记本电脑网络摄像头拍摄照片。最初我使用的图像大小为640 x 840。这些配置在我现在使用的示例中给出

   const int VIDEODEVICE = 0; 
   const int VIDEOWIDTH = 640; 
   const int VIDEOHEIGHT = 480; 
   const int VIDEOBITSPERPIXEL = 24;
在声明捕获对象时传递这些值,即

 cam = new Capture(VIDEODEVICE, VIDEOWIDTH, VIDEOHEIGHT, VIDEOBITSPERPIXEL, picCamera);

一切正常。但我想照护照尺寸的照片,也就是说,宽度越小,高度越高。当我改变常数的宽度和高度时,DLL停止工作。任何人请告诉我如何更改宽度和高度?

您可以更改相机设置中定义的分辨率。例如320x240等。。创建快照图像时,请调整位图对象的大小,并可能裁剪其侧面。例如,我使用了以下代码:

IntPtr m_ip = IntPtr.Zero;
m_ip = capture.Click();
Bitmap b = new Bitmap(640, 480, capture.Stride, PixelFormat.Format24bppRgb, m_ip);
b = ResizeBitmap(b,220,220); //The size of your box
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
pictureBox2.Image = b;

private static Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height)
{
   Bitmap result = new Bitmap(width, height);
   using (Graphics g = Graphics.FromImage(result))
   g.DrawImage(sourceBMP, 0, 0, width, height);
   return result;
}

您可以更改相机设置中定义的分辨率。例如320x240等。。创建快照图像时,请调整位图对象的大小,并可能裁剪其侧面。例如,我使用了以下代码:

IntPtr m_ip = IntPtr.Zero;
m_ip = capture.Click();
Bitmap b = new Bitmap(640, 480, capture.Stride, PixelFormat.Format24bppRgb, m_ip);
b = ResizeBitmap(b,220,220); //The size of your box
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
pictureBox2.Image = b;

private static Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height)
{
   Bitmap result = new Bitmap(width, height);
   using (Graphics g = Graphics.FromImage(result))
   g.DrawImage(sourceBMP, 0, 0, width, height);
   return result;
}