The scaled image opens in Image2 instead of Image1 lazarus / 39-Graphics ---------------------------------------------------------------------- kolbjoern · 2018-12-16 17:22 I have a form with two TImage components, Image1 and Image2 and a button to start the program. The procedure shown in the attachment and below. When running I expected the image to be opened in Image1 but the scaled image opens in Image2. Why? The unscaled image is shown in Image1. procedure scaleImage; var   Img: TImage; begin   OpenDialog1.Execute;   if (OpenDialog1.Files.Count = 1) and (FileExists(OpenDialog1.FileName)) then   begin     Image2.Picture.LoadFromFile(OpenDialog1.FileName);     Img := Image2;     Img.Proportional:= True;     Img.Width := 400;     Img.Height:= 267;     Image1.Picture := Img.Picture;   end; end; Kolbjørn ---------------------------------------------------------------------- wp · 2018-12-16 17:54 You (unnecessarily) assign the Image2 to a variable img - this is just am abbreviation for typing. So, whenever you write img you mean Image2. You set img.Proportional to true - because img=Image2 this sets Images2.Proportional to true. This scales the raw image to the size of image2 (I thought that it is required also to set Stretch to true, but this seems to be wrong). Then you set Image1.Picture := img.Picture. This does not copy the scaled image, it copies the raw data which are in Img = Image2. Therefore, you have the unscaled image im Image1 and the scaled image in Image2. ---------------------------------------------------------------------- kolbjoern · 2018-12-16 19:03 Thank you wp. I thought the contents of Image2 was copied into img and then I could manipulate img independently of the content of Image2 just like b := 3;a := b + 1 with the result a = 4; b = 3. I am new to image handling and obviously have lots to learn :-). Kolbjørn ---------------------------------------------------------------------- lucamar · 2018-12-16 21:43 Try something like this (untested) 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 scaleImage;begin  OpenDialog1.Execute;  if (OpenDialog1.Files.Count = 1) and (FileExists(OpenDialog1.FileName)) then  begin    Image2.Picture.LoadFromFile(OpenDialog1.FileName);    Image1.Proportional:= True;    Image1.Width := 400;    Image1.Height:= 267;    Image1.Picture.Assign(Image2.Picture);  end;end; It's not only a question a question of image handling, it's a question of object handling. Using ":=" simply copies the reference so the two variables point to the same object. The Assign method, however, should copy the fields from one object to another if either one know  how to do it. ---------------------------------------------------------------------- kolbjoern · 2018-12-17 15:57 I had simplified my program example to show what I was asking for. I did not think of it as object handling for some reasons. So thank you for reminding med. And yes, your code works. The reason for my question was that I would show a miniature of the image, adding some data to the image and then save it i full size, not the scaled copy. Thanks to you both I now have a better understanding of how to do this. Kobjørn ---------------------------------------------------------------------- lucamar · 2018-12-17 16:46 Quote from: kolbjoern on December 17, 2018, 04:57:38 pmThe reason for my question was that I would show a miniature of the image, adding some data to the image and then save it i full size, not the scaled copy. Note that you can get by with just one TImage. When you set Stretch, Proportional, etc. the only thing that changes is how Picture is drawn, not the underlying picture data. ---------------------------------------------------------------------- User137 · 2018-12-17 16:54 I guess you'll want scaling done with Picture.Canvas.CopyRect(), if you want the saved file to be different size than original. ---------------------------------------------------------------------- lucamar · 2018-12-17 17:14 Quote from: User137 on December 17, 2018, 05:54:53 pmI guess you'll want scaling done with Picture.Canvas.CopyRect(), if you want the saved file to be different size than original. He said he wants to save the full-sized image. Even if it were not so, it would be better to use StretchDraw for scaling--that is, besides the advanced resamplers in the FCL. ---------------------------------------------------------------------- kolbjoern · 2018-12-18 19:46 I have experimented with your suggestions and yes you are right of course. Thank you a lot for using your time on me. I have not used Pascal for many years and found it was the time for refreshing my knowledge about this interesting language a bit. Perhaps image handling was a bit too difficult for me as a start. Kolbjørn