Alpha blending isn't that hard for me except when the destination also has an alpha channel.

I've tried multiplying with the destination alpha channel into the RGB calculation.

My problem currently is semi-transparent pixels, either opaque or transparent destination alpha works ok.

VB Code:
  1. ' RGBA = destination
  2. 'c(r,g,b) = source
  3. 'Opacity = source opacity
  4.              Sa(0) = Opacity / 255
  5.              Sa(1) = A / 255
  6.  
  7.                
  8.                clsDIB.Red = cR * Sa(0) + cR * (1 - Sa(1)) + R * (1 - Sa(0)) * Sa(1)
  9.                clsDIB.Green = cG * Sa(0) + cG * (1 - Sa(1)) + G * (1 - Sa(0)) * Sa(1)
  10.                clsDIB.Blue = cB * Sa(0) + cB * (1 - Sa(1)) + B * (1 - Sa(0)) * Sa(1)
  11.                clsDIB.Alpha = Opacity * (1 - Sa(1)) + A