YAP (yet another project) – Webcam software … image processing edition

image

So I saw that Jeff Sandquist’s webcam solution had some issues and I was kind of surprised there wasn’t a decent solution out there.  I won’t pledge a great application, but I will pledge a decent one that can be altered to fit your needs.

So I have three requirements for this:

  • Uploads to FTP
  • Uploads to flickr also
  • Can embed a time stamp with a nice transparency

From a high level, here is the application’s load function.  Note this is just the image processing part.  Since this is GDI+, we want to be very careful to dispose of our graphic objects since we don’t want memory leaks.  Now I have not verified this is memory leak free so be warned.

We do the resize so we don’t resize the text we’ll pop on top of the image.  I did some research and found some nice guy did a bit of help for me when it came to resizing over at Switch On The Code.  I won’t really repeat that code as they’ve already done it.  I tweaked it slightly but for the most part, their code works.

var returnValue = new Bitmap("C:\\test.jpg");
returnValue = (Bitmap)resizeImage(returnValue, new Size(250, 400));

int rectHeight = 25;
addRectangle(returnValue, 0, returnValue.Height - rectHeight, 
	returnValue.Width, rectHeight, Color.FromArgb(180, Color.Black));
addImageText(returnValue, "Hi from Mix'09", 0, 
	returnValue.Height - rectHeight, Color.White);
pictureBox1.Image = returnValue;

After that, we’ll pop on the rectangle overlay then put on the text. 

private static void addImageText(Image imgToAddText, 
	string text, int x, int y, Color color)
{
	using (Graphics g = Graphics.FromImage(imgToAddText))
	{
		g.SmoothingMode = SmoothingMode.AntiAlias;
		g.DrawString(text, 
			new Font("Arial", 20, GraphicsUnit.Pixel), 
			new SolidBrush(color), 
			x, y);
		g.DrawImage(imgToAddText, 
			0, 0, imgToAddText.Width, imgToAddText.Height);
	}
}

private static void addRectangle(Image imgToAddRect, 
	int x, int y, int width, int height, Color color )
{
	using (Graphics g = Graphics.FromImage(imgToAddRect))
		g.FillRectangle(
			new SolidBrush(color), 
			new Rectangle(x, y, width, height));
}

So after all that, here is the image after all the processing.  Next up, DirectShow.Net integration followed by some FTP and Flickr action.

Jeremiah Morrill Apr 17, 2009 @ 10:08 PM

# re: YAP (yet another project) – Webcam software … image processing edition
1992 called and they want their GDI back! ;)

Where's the WPF bro bro? You could use all the sweet gfx compositing abilities. I have a VideoCaptureElement in my WPF MediaKit for webcams in WPF. Also Tamir has one on codeplex called WPFCap.

Take it easy bud,

-Jer

Clint Apr 18, 2009 @ 12:24 AM

# re: YAP (yet another project) – Webcam software … image processing edition
I did not know that you guys did nor what gfx is. As with most programmers, I failed and reverted back to what I know.

Good to know, I'll update it.

Post a Comment

Please add 3 and 4 and type the answer here: