views:

1552

answers:

3

I have two bitmap images. One contains a picture taken with a usb camera. The other will contain a shape, like a rectagle, but it can also be a trapezoid, or lets say, a random shape with only one color in it. The rest of the image is white right now.

The two images aren't of the same size but scaling algorithms aren't the most difficult part here, so lets assume they are of the exact same dimensions.

I want to show my shape on the usb camera picture. The white part will be considered as transparent for the combinaison purpose. Right now I'm thinking of editing the image pixels by pixels, but I'm searching for an API which will do it for me.

So if I take a picture with a house in the middle of it and overlay a red rectagle, the resulting image will have the original picture with a red rectangle around the house.

I'm using .NET if this can help. I could also use win32 API if it contains some useful functions.

Edit : I accepted the answer since it put me on the right track. This is actually super easy to do.

Bitmap^ overlay_image = gcnew Bitmap("overlay.bmp");
Bitmap^ original_image = gcnew Bitmap("original.bmp");
overlay_image->MakeTransparent(Color::White);
Graphics^ g_original = Graphics::FromImage(original_image);
g_original->DrawImage(overlay_image, 0, 0);

Voilà, original_image now has a red rectangle over it. It is actually fast enough for my 30fps usb camera so I can get it in real time.

There is no scaling done right now. Also, it assumes that the overlay image background is white, which will be made transparent.

+1  A: 

If you are using the full .NET platform, System.Drawing.Imaging has functions for alpha channels and masking:

http://www.codeproject.com/KB/GDI-plus/alphafx.aspx

Godeke
+1  A: 

One quite robust library worth looking at is ImageMagick. They even have a .NET port of the library. It can do things related to transparency, shapes, and superimposing.

I might try using the command-line versions first (the convert or composite command, for example) to see if you can make them do what you want. If that works, then you ought to be able to implement that same functionality using their libraries.

rascher
A: 

Please help with combine two images with one being transparent with using C++ not .NET

Please any examples.

Thanks!

sakrist