Sizing Image captured from webcam to Picturebox using avicap32dll In C#
<p>I have actually come across a problem with this myself. I'm hoping that someone can explain this to me. I'm currently experimenting with C# for web cam capture just read your article regarding send message as I have a problem setting the scale of the captured video from the cam to the size of the Picture box that I'm using Unfortunately I don't seem to be able to get this right I've found that by setting the scale to -1 as per your discussion that scale appears to adjust but not to the size of the picture box on the form I'm setting this inside my class and know that Its being set to my object on my form Inside my other class which I'm instantiating from the form I'm using the avicap Dll for obtaining the captured image </p>

<pre><code>hHwnd = capCreateCaptureWindowA(ref DeviceIndex, WS_VISIBLE | WS_CHILD, 0, 0, 160, 120, oHandle.ToInt32(), 0);

 // Connect to device
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT,DeviceID, IntPtr.Zero) != (IntPtr)0)
{
     // Set the preview scale
   SendMessage(hHwnd, WM_CAP_SET_SCALE, (IntPtr)(-1), IntPtr.Zero);
    // Set the preview rate in terms of milliseconds
   SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, (IntPtr)66, IntPtr.Zero);

     // Start previewing the image from the camera
   SendMessage(hHwnd, WM_CAP_SET_PREVIEW, (IntPtr)1, IntPtr.Zero);

   // Resize window to fit in picturebox
   SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, Container.Height, Container.Width, SWP_NOMOVE | SWP_NOZORDER);

}
else
{
    // Error connecting to device close window
    DestroyWindow(hHwnd);
}
</code></pre>

<p>However when passing the Picture box to the class and starting the connection </p>

<p>Which I do in my form like this </p>

<pre><code>oWebCam = new WebCam();
oWebCam.Container = pictureBox1;
</code></pre>

<p>My captured Image takes up the height but not the width In other words I don't seem to be able to stretch the image according to the size of the Picture Box </p>

<p>What am I doing wrong? can someone suggest anything?</p>
