Repaint shape over an image

I have an optimization problem.
I’m trying to draw a little shape over an image and sometimes have to repaint the shape but the image behind doesn’t always change.
I tried with two classes, both with their own paint method.
The paint method of the first class only draw the image and call a method of the second class that draw the shape.
The paint method of the second class only call the method to paint the shape.
The problem with this method is that when calling a repaint for the shape only, the image is not drawn and only the shape appears.
This is why i would like to know if there is a way to repaint the shape without having to repaint the entire image or do i have to repaint the entire image every time?

Hello @flardy,

To avoid repainting more than needed, you can use the clip functions on a Graphic Context. You can also restrict the repaint request by using this function with the parameters x, y, width, height.


Hello @pierre.rivron,
Thank you for your answer.
The repaint on the restricted area seems to works well for my problem.
Haven’t tested the clip functions yet but i’ll try it out and see which one works best.

you can also use Bridge Pattern to dividing your method which can draw your shape or image more flexibly.