Tanveer
Tanveer

Reputation: 2087

Changing dimensions of image capturing using DirectShow

i am using DirecShowLib-2005.Dll to take picture from my Laptop webcam. Initially i am using image size 640 x 840. These configurations were given in example that i am using as it is

   const int VIDEODEVICE = 0; 
   const int VIDEOWIDTH = 640; 
   const int VIDEOHEIGHT = 480; 
   const int VIDEOBITSPERPIXEL = 24;

These values are passed while declaring Capture object i.e.

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

Every thing works fine. But i want to take picture in Passport Size i.e. with less width and more height. When ever i change width and height of constants DLL stops working. Anyone please guide me that how i can change the width and height?

Upvotes: 1

Views: 1086

Answers (1)

K. Roland
K. Roland

Reputation: 342

You can change it for those resolutions, that are defined in the camera's settings. For example 320x240, etc.. When you create the snapshot image resize the Bitmap object and maybe crop the sides of it. For example, I used this code:

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;
}

Upvotes: 1

Related Questions