Blend two Images in one Image


#1

Is there any way to blend two Images?, ex: 

Image a;
Image b;

Image c = a.blend (b, alpha);

(It is not in a Component)


#2

Ok i've found how to do it:

        Image outputImage = (load or create empty)
        Image a = loadimageA
        Image b = loadImageB

        ScopedPointer <Graphics> g = new Graphics (outputImage);
        g->drawImageAt (a, 0, 0);
        g->drawImageAt (b, 0,0);

 


#3

you're just writing one image over the other, so I think it's an 'overlay'? Which makes sense if the second image has transparent sections, otherwise you will only see the second image.


#4

Yes, the second image has transparent background,  to adjust the alpha channel I add .multiplyAllAlphas() the the second image


Image outputImage = (load or create empty)
Image a = loadimageA
Image b = loadImageB
ScopedPointer <Graphics> g = new Graphics (outputImage);
g->drawImageAt (a, 0, 0);
g->drawImageAt (b.multiplyAllAlphas(0.6f) , 0,0);

 


#5

Just for the benefit of any beginners who read this thread, here's a better example of how to write that:

Image createCompositedImage (Image background, Image foreground, float alpha)
{
    Image result = background.createCopy();

    Graphics g (result);
    g.setOpacity (alpha);
    g.drawImage (foreground, 0, 0); // obviously this ignores the fact that they may be different sizes

    return result;
}

:)


#6

What blend modes are supported and how do you set the blend mode?


#7

Only normal compositing is supported.