"Copy" alpha channel from a memory image to another


but i got wrong result.

my target is draw an image with some specified shap masked.

my steps:

1, create a pie shape:

Path arc;
static const float FROMARC = 270.0f * RADIAN;
arc.addPieSegment(0, 0, width, height + 5.0f, FROMARC, FROMARC + m_fCurArcAngle, 0.0f);

2, update the “canvas”:

m_pathCache->clear(m_pathCache->getBounds());    //clear then now it's transparent
juce::Graphics ig(*m_pathCache);
ig.setColour(Colour(0xff000000));    /draw the pie with black to the memory image

3, final step to apply the memory ‘shape’ image to the display image:

FillType ft(*m_pathCache, AffineTransform::identity);
g.drawImageAt(m_imgMaskBg, 0, 0, true);     //final display

but… on my screen, the result is a black pie!
something wrong??
i need help!! guys~


Maybe you should use Graphics::reduceClipRegion to clip to your image alpha?


the region has same size and coords with the display image, 

so i think no need to call this API?

i just made a picture to explain what i want, and my code at above as you see what:

arc -> the black pie path

m_pathCache -> the bitmpa cache to draw the pie path

m_imgMaskBg -> the original display image (and sould be the correct result to display)

thanks for your so amazing framework jules!


Right, so clip to the path you want with reduceClipRegion, then just draw the entire image.

(I don't recommend using images though - this kind of thing is better done with vector graphics)


this really impressed me!!

i thought that clip region only could apply square shape....

now it works very well, the memory bitmp is unnecessary.

many many thanks jules.