I really don't know if this is a bug, or it's me who doesn't understand it.
Take a TForm, with a Timage and a TButton.
This is the code of the TButton OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
var
Vertex : array[0..3] of TPoint;
begin
with Image1.Picture.Bitmap do
begin
Width := ClientWidth;
Height := ClientHeight;
with Canvas do
begin
Brush.Style := bsSolid;
// red square
Vertex[0].X := 0; Vertex[0].Y := 0;
Vertex[1].X := 20; Vertex[1].Y := 0;
Vertex[2].X := 20; Vertex[2].Y := 20;
Vertex[3].X := 0; Vertex[3].Y := 20;
Brush.Color := clRed;
Polygon(Vertex);
// green square
Vertex[0].X := 20; Vertex[0].Y := 20;
Vertex[1].X := 40; Vertex[1].Y := 20;
Vertex[2].X := 40; Vertex[2].Y := 40;
Vertex[3].X := 20; Vertex[3].Y := 40;
Brush.Color := clGreen;
Polygon(Vertex);
end;
end;
end;
Obviously when user click on the button, two squares are drawn, a red one on the top-left and a green one on the bottom-right of the Timage object.
In fact, in case (A) Timage has Left:=0; Top:=0; Width:=40; Height:=40; I get something like that:
RRBBX
RRBBX
BBGGX
BBGGX
XXXXX
Legend:
R=RED COLOR
G=GREEN COLOR
B=BLACK COLOR (canvas background)
X=form background (background)
But in case (B) Timage has Left:=10; Top:=10; Width:=40; Height:=40; I get something like that:
XXXXX
XRRBX
XRRBX
XBBGX
XXXXX
which IS NOT WHAT I EXPECTED :shock:
I had expected something like that:
XXXXX
XRRBB
XRRBB
XBBGG
XBBGG
Am I wrong to expect that or what?
Thanks in advance to who will provide me with an explanation! :wink: