clipToImageAlpha won't work on Windows

I’m using clipToImageAlpha() in my plugin to ensure that user-supplied images are transparent in certain areas. It works like a charm on Mac, but on Windows the entire image becomes transparent instead.

Here is my code:

void makeHolesInImage(Image &image)
{
    Graphics g(image);
    auto &context = g.getInternalContext();
    context.clipToImageAlpha(clippingImage, AffineTransform());
    image.clear(image.getBounds(), Colour(0.0f, 0.0f, 0.0f, 0.0f));
}

Any ideas what I might be doing wrong? Or is it a problem with JUCE? This is on JUCE 6.1.4, by the way.

No takers? I guess I’ll just have to skip that feature, then.

Please don’t use the internal context (it’s internal for a reason). Simply use

juce::Graphics::reduceClipRegion ( const juce::Image& image, const juce::AffineTransform& transform )

It should do exactly what you want.

Thanks for the reply!

I tried your suggestion now, but unfortunately I get the exact same result: Works as expected on Mac, but on Windows the whole image becomes transparent.

Here’s the code, maybe I’m still using it wrong?

void makeHolesInImage(Image &image)
{
    Graphics g(image);
    g.reduceClipRegion(clippingImage, AffineTransform());
    image.clear(image.getBounds(), Colour(0.0f, 0.0f, 0.0f, 0.0f));
}

You don’t have to clear the source image, but instead draw the source image into the new graphics context.

I’m not sure I follow? Could you show me how I should modify the code I posted above to do that?

I tried replacing image.clear() with g.drawImage(), but that doesn’t seem to modify the image at all, so now the image is completely unchanged instead, and on both Mac and Windows.

OK. First, you will have to create a new bitmap, the same size as the bitmap you want to punch a hole into. It has to be cleared with black transparent alpha.

Then you create a graphics context with the new image as the target.

Then you reduce the clipping region with your clipping image.

Then you draw the customer’s image into the new bitmap.

Ah, yes, of course! I was still stuck on the idea of modifying the original image, sorry for being a bit dense…

Drawing into the new image worked perfectly! Thank you so much for helping me out with this!