Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

Webcam Still Capture

by Jim Oct 30, 2006 10:28 PM

I got a webcam, and of course I had to access it with some .NET code. I probably could have found a program to upload images to the website, but that wouldn't have been any fun.

I found a great little library on Nauman Leghari's Blog that got me most of the way there. It gave me a video window, but needed one more function to capture a still image from the webcam:

/// <summary>
/// Capture a still image and return it
/// </summary>
/// <returns>A Bitmap image</returns>
public System.Drawing.Image CaptureStillImage()
{
    System.Drawing.Image img = null;
 
    // Tell the device to grab a frame to the clipboard
    int rslt = SendMessage(deviceHandle, WM_CAP_EDIT_COPY, 0, 0);

    // Look for the data on the clipboard            
    IDataObject iData = Clipboard.GetDataObject();
    if (iData.GetDataPresent(DataFormats.Bitmap))
    {
        img = (System.Drawing.Bitmap)iData.GetData(DataFormats.Bitmap);
    }
    return img;
}

Tags:

Code

Tray Icon

by Jim Oct 28, 2006 8:14 AM

The tray icon that I created for my application looked like a dog next to all the other beautiful icons in my system tray. Look at the rough edges on the smiley face.

At first I thought that windows was choosing the wrong size icon for the system tray. My icon file has 32x32 and 16x16 icons, and windows was using the correct one in every other situation. Then I realized that the problem was loading the icon from my exe's resources. I was doing this:

mIcons(0) = New Icon( _ 
  GetType(MainForm).Assembly.GetManifestResourceStream("EventWatcher.EventWatcher.ico"))

When I should have been doing this:

mIcons(0) = New Icon( _ 
  GetType(MainForm).Assembly.GetManifestResourceStream("EventWatcher.EventWatcher.ico"), _ 
  New Size(16, 16))

The .NET icon object doesn't load the whole icon file, just one icon. So Windows never got a chance to choose the right one. By default, it was loading the 32x32 icon, probably just because it was first in the list.

Tags: ,

Code