Clip region for strange shapes on transparent background


Is this a good way of reducing the clip region for images which are mostly transparent?

(*imgBuffer).createSolidAreaMask( m_NewClipRegion , alphaThreshold );
g.reduceClipRegion(m_NewClipRegion );

Or is createSolidAreaMask() actually more expensive that the drawing of the image using g.drawImageAt () ?

What do you think?

I don’t really understand what you’re trying to do, but it’s certainly an expensive operation to clip to an image’s alpha channel like that… I can’t imagine any situation where it’d be faster to do that unless you really need to.

Thanks jules! What I want to do is avoid updating pixels that havent changed in large rectangular components that are mostly transparent but have non-transparent regions in the center. I could make coarse “solid area masks” with just a couple of rectangles pretty inexpensively so I could try and see if that would help speed up the painting.

I can’t really see how it’d help…? If the things you’re drawing are within this solid region, then it doesn’t matter whether you clipped the graphics context or not. And if they go beyond this solid region, then you probably don’t actually want to clip them…?

Really? I thought I could save some cycles by reducing the size of the region that is to be repainted by reducing the clip region. Why doesn’t clipping matter? Is it because of the transparency?


Maybe you’re confusing opaque components (which are handy to avoid drawing things that lie underneath the component) with the graphics context’s clip region?

Well, I admit I am confused :frowning: Isn’t the graphics context’s clip region the region that gets painted on?

I thought it worked like this;

  • in paint() the graphics context comes with a clip region which by default has the same width and height as the component
  • reduceClipRegion() can be used to make the clip region smaller, the clip region could for example be changed to the lower half of the component
  • if for example drawImageAt() is used (with an image the size of the component), only the lower half of the image would be drawn
    into the lower half of the component

Have got it right?

Well, that’s more-or-less right, but I don’t understand why you think changing the clip could affect performance?

I was thinking that fewer cycles would be used to plot a smaller region. But maybe drawImage() is very inexpensive so it doesn matter if the clip region is 5% or 100% of the whole image?

Sorry, I’m really just totally confused by what you mean…

Obviously the less you draw, the faster it is. But changing the clip region will only make a difference if the thing you’re drawing actually goes outside the new clip region. And if it does, the result will be different. There’s nothing you could possibly do with the clip region that would make a drawing operation faster without actually changing the drawing that gets performed.

Sorry for my bad explanation :oops: Knowing that clipping to an image’s alpha channel is very expensive was what I needed to know.

Thanks for your help jules, really appreciate it!