JusJJ 0 Posted May 10, 2023 Hi, Is there a way to prevent drawing outside the canvas? If, for example, I have a rectangular shape on which I draw an ellipse and I want to limit the drawing to the area of the shape. procedure TForm1.shapePaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF); var x,y :integer; circle : TRectF; begin x:=round(shape.Width/2); y:=round(shape.Width/2); circle:=TRectF.Create(x-190,y-190,x+100,y+100); shape.Canvas.Stroke.Color:=TAlphaColors.Black; shape.Canvas.DrawEllipse(circle,50); end; Now part of it is also drawn outside the shape. Share this post Link to post
PeaShooter_OMO 11 Posted May 10, 2023 (edited) Have a look at Clipping Regions.. Here is a little example (Obviously this for the Windows platform): https://docwiki.embarcadero.com/CodeExamples/Sydney/en/ClipRect_(Delphi) Edited May 10, 2023 by PeaShooter_OMO Share this post Link to post
Remy Lebeau 1436 Posted May 10, 2023 8 hours ago, PeaShooter_OMO said: Have a look at Clipping Regions.. Here is a little example (Obviously this for the Windows platform): https://docwiki.embarcadero.com/CodeExamples/Sydney/en/ClipRect_(Delphi) Clipping is the right solution. But ClipRect() won't work for FMX. In FMX, to clip a drawing to a rectangular area, use the TCanvas.IntersectClipRect() and TCanvas.ExcludeClipRect() methods. To clip in a non-rectangular area, use TCanvas.DrawPath() and TCanvas.FillPath() instead. Share this post Link to post