Originally Posted by tscorpio
I can's see any alternative to looping through the pixels. Since you say looping through the pixels is slow, perhaps you are not yet familiar with the LockBits method which allows you to treat the image as a byte or integer array. The integer version could easily provide speed gains of over 100x over GetPixel/SetPixel for large images. The speed gain depends partly on how efficient you make your inner loop.
I posted a LockBits wrapper class (FastPix) to the CodeBank which makes it simpler to apply the LockBits method. See the "rapid pixel processing" link in my signature below. Assuming you have downloaded the FastPix class and added it to your project, and includeColor is the color you want to keep, you could code what you want to do optimally like this:
The effect of this is to set the pixels of the wanted color to 50% opacity and all other pixels to 0% opacity. You can then paint bmpA onto ImageB using Graphics.DrawImage (which GDI+ does pretty efficiently).
Dim colorValue As Integer = includeColor.ToARGB
Dim alphaMaskValue As Integer = &HFFFFFF
Dim alphaValue As Integer = &H80000000
Dim bmpA As New Bitmap(ImageA)
Using fp As New FastPix(bmpA)
Dim pixels() As Integer = fp.PixelArray
For i As Integer = 0 To pixels.Length - 1
Dim pixelValue As Integer = pixels(i)
If pixelValue = colorValue Then
pixels(i) = pixelValue And alphaMaskValue Or alphaValue
pixels(i) = 0