How to determine the area of ​​the shape built in Shape (Delphi 7)? Just to clarify, not the area of ​​the component is needed, but the area of ​​the figure that the component draws. I have no idea where to get the data for the formula for calculating the area ... If there are any ...

    2 answers 2

    If the property of the Shape component of Shape1 is not equal to stRoundRect or stRoundSquare, then everything is simple:

      procedure TForm1.Button1Click (Sender: TObject);
     Var
       S: Extended;
     begin
       S: = 0;
       If (Shape1.Shape = stRectangle) Then S: = Shape1.Width * Shape1.Height
       Else If (Shape1.Shape = stEllipse) Then S: = Shape1.Width * Shape1.Height * Pi / 4
       Else If (Shape1.Shape = stSquare) Then
         If (Shape1.Width> Shape1.Height) Then
           S: = Sqr (Shape1.Height)
         Else S: ​​= Sqr (Shape1.Width)
       Else If (Shape1.Shape = stCircle) Then
         If (Shape1.Width> Shape1.Height) Then
           S: = Pi * Sqr (Shape1.Height / 2)
         Else S: ​​= Pi * Sqr (Shape1.Width / 2)
       Else ShowMessage ('This is beyond my computational abilities!');
       If (S = 0) Then Exit
       Else ShowMessage ('S =' + IntToStr (Round (S)));
     end;
    

    The complexity of the calculations in cases where the property of the Shape Shape1 component is equal to stRoundRect or stRoundSquare is that it is necessary to obtain the area of ​​an astroid (this is not the area captured by the figure resulting from rounding, its area is S = 3 Pi R / 8). The main thing is to find the area to subtract from the area of ​​a square or rectangle, and I still don’t know how to find its area, since the radius of the rounding depends on the size of the Shape component itself.

    • Thank you all right) - Zein

    As an option, fill the entire shape with one color, and then count how many filled pixels