Reputation: 3637
I am combining two RGB images, pixel by pixel, each of different sizes, while combining them I'd like the one that is on top, which is smaller in size to be transparent regarding two the bigger one in the background, like a see-through. What processing should I do? Cause right now..merging the images resumes just to replacing pixels. How can I achieve this transparency? I'm using c++.
Upvotes: 3
Views: 2702
Reputation: 308206
As noted in the comments, the basic formula for blending two images is newColor = ColorTop * alpha + ColorBottom * (1-alpha)
.
Some images contain an alpha value per pixel, but from your brief description this doesn't sound like the case you're interested in. You just want a constant transparency applied to the entire upper image. Let's assume you want 33% transparency for example:
alpha = 0.33
Rnew = (Rtop * alpha) + (Rbottom * (1.0 - alpha))
Gnew = (Gtop * alpha) + (Gbottom * (1.0 - alpha))
Bnew = (Btop * alpha) + (Bbottom * (1.0 - alpha))
Upvotes: 2