Main form takes on dimensions of loaded bitmap lazarus / 39-Graphics ---------------------------------------------------------------------- jave · 2018-10-16 10:41 Hi all, Me again. lol I've made some changes to my code so that when a bitmap file is loaded, the image displays on the 2nd form.  This works fine, however when I click on a button to process the bitmap image, my main form takes on the dimensions of the loaded bitmap.  What am I doing wrong? Code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button4Click(Sender: TObject);begin  BitMap2 := TBitMap.create;  BitMap2.Assign(BitMap1);  width := BitMap2.Width;  height := BitMap2.Height;  Label3.Caption := IntToStr(width);  Label4.Caption := IntToStr(height);  for px:= 0 to width do begin    for py:= 0 to height do begin        // get colour        colour1 := BitMap2.Canvas.Pixels[px,py];        colour2 := BitMap2.Canvas.Pixels[px+1,py];        if (colour1 <> colour2) then begin // if pixels do not match           BitMap2.Canvas.Pixels[px,py] := clRed;           // colour1 := BitMap1.Canvas.Pixels[px,py];      end      end;  end;  for py:= 0 to height do begin      for px:= 0 to width do begin        // get colour        colour1 := BitMap2.Canvas.Pixels[px,py];        colour2 := BitMap2.Canvas.Pixels[px,py+1];        if (colour1 <> colour2) then begin // if pixels do not match           BitMap2.Canvas.Pixels[px,py] := clRed;           // colour1 := BitMap1.Canvas.Pixels[px,py];      end      end;  end;  Label6.Caption := 'Image processed.';  Form3.Image1.Canvas.Draw(0,0,BitMap2);  Form3.Image1.Stretch := True ;end;  I'm pretty sure I don't need the 2nd bitmap but added it as I was trying a few different things.  Thanks! ---------------------------------------------------------------------- JuhaManninen · 2018-10-16 10:53 You explicitly set width and height of TForm1 at lines 5 and 6 of your listing. ---------------------------------------------------------------------- jave · 2018-10-17 06:01 Okay, so how can I obtain the width and height of the loaded bitmap image? ---------------------------------------------------------------------- wp · 2018-10-17 07:50 Declare width and height as local variables. But you must be aware that these names are already defined by the form (that's the reason why the size of the form changes in your code), fpc in mode objfpc rejects local variables with this ambiguity. Therefore, name them "w" and "h", or "lWidth" and "lHeight", "l" for "local": Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button4Click(Sender: TObject);var  lWidth, lHeight: Integer;   // <--- NEWbegin  BitMap2 := TBitMap.create;  BitMap2.Assign(BitMap1);  lWidth := BitMap2.Width;  lHeight := BitMap2.Height;  Label3.Caption := IntToStr(lWidth);  Label4.Caption := IntToStr(lHeight);  for px:= 0 to lWidth do begin    ... ---------------------------------------------------------------------- jave · 2018-10-17 08:19 Ah okay.  Many thanks!!