Menu

Clipping functions

2021-12-24
2021-12-25
  • Herbert M Sauro

    Herbert M Sauro - 2021-12-24

    Are there any functions to clip drawing operations to a given 2D area? I have my own clipping method I wrote ages ago which I can use but I wanted to ask if there is anything built into TIMage32? I searched the API docs but nothing turned up.

     

    Last edit: Herbert M Sauro 2021-12-24
  • Angus Johnson

    Angus Johnson - 2021-12-24

    Hi again Herbert.
    There are a couple of ways to clip an image (assuming you're not just clipping a simple rectangular region). If you're performing a single (once only) clip operation with a given polygon shape then the Img32.Draw.ErasePolygon procedure is probably the simplest (and likely the most efficient too). But if your clip polygon is likely to be used more than once then create a clip image mask and use TImage32's CopyBlend function passing Img32.BlendMask as the blend function. (You can see this latter approach used in Img32.Layers.)

     

    Last edit: Angus Johnson 2021-12-24
  • Herbert M Sauro

    Herbert M Sauro - 2021-12-24

    Thanks for getting back and for all your help. What if I just wanted to clip a simple rectangular area, would I use ErasePolygon? I'm currently using my own clipping code to clip lines which works so far.

    I wanted to try out TImage32 instead of using GDI+ which I've used in the past. So far, its worked out quite well. As an experiment, in the last few days I wrote a simple plotting component . It doesn't use a lot of the TImage32 API but enough for my purpose. I'm put the code up on GitHub once it's tidied up a bit more so that others can see it. Thanks for contributing TImage32.

     
  • Angus Johnson

    Angus Johnson - 2021-12-25

    Thanks for getting back and for all your help.

    You're welcome.

    What if I just wanted to clip a simple rectangular area,

    image.FillRect(rec, clNone32);

    in the last few days I wrote a simple plotting component

    Looks good.
    Also, there's a new InterpolatePoints function in Img32.Extra (line 2822ff) that you might find useful though it hasn't quite made it to the release package. (Note also the precondition comments in the interface section.)

     

    Last edit: Angus Johnson 2021-12-25