I am trying to do an alpha blending in c#. So my actual code for this is:
final.Red = (pencil.Red * pencil.Alpha) + (background.Red * (1.0f - pencil.Alpha));
final.Green = (pencil.Green * pencil.Alpha) + (background.Green * (1.0f - pencil.Alpha));
final.Blue = (pencil.Blue * pencil.Alpha) + (background.Blue * (1.0f - pencil.Alpha));
This is working fine if the background pixel has no opacity. But what is the calculation for the colors if the background pixel has opacity?
Ok I managed it by myself. Was not as complicated as I thought. Heres is my solution:
With this it is working on every backgound opacity.