Solved - Unable to set image background to white lazarus / 21-General ---------------------------------------------------------------------- Wilko500 · 2021-01-22 00:38 I had this working in previous test program but after moving into my full project it did not.  The difference is down to different order of operations. Under test I was -creating a form dynamically with TImage (align set to acClient) with random size -setting the background to white -then drawing on the image. The new process -creates the form dynamically the same was with TImage (align set to acClient) with a fixed size -calculates coords and sets form to new size/position -then draws on the image. What happens is that the area drawn to (cleared) is the same size as the form that the dynamically created form is based on. Quotefrm.Image1.Canvas.Line(0, 0, frm.image1.Width-1, frm.image1.Height-1); frm.Image1.Canvas.Line(0, frm.image1.Height-1,frm.image1.Width-1 ,0); draws the red lines and seems to understand the actual image1 size. Quotefrm.Image1.Canvas.FillRect(frm.image1.BoundsRect);but this which I found somewhere seems not to. I am missing something but what? The attached project Test12.zip contains just enough of my program to simulate the problem Thanks ---------------------------------------------------------------------- Handoko · 2021-01-22 04:09 Problem fixed. Download and try the modified code below. The issue happened because you resized the form. I believe for lightweight reason TImage does not 'renew' its canvas after being resized. You need create a new canvas to replace the old but because replacing the canvas is not allowed, so I replace the whole TImage directly. 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 TfrmPage.FormResize(Sender: TObject);var  Temp: TImage;begin  Temp      := TImage.Create(Self);  Temp.Parent := Self;  Temp.Width  := Width;  Temp.Height := Height;  Temp.Canvas.Clear;  Temp.Canvas.CopyRect(Temp.BoundsRect, Image1.Canvas, Temp.BoundsRect);  Image1.Free;  Image1 := Temp;end; The workaround clearly has limitations. For a good solution you will need to think many things. How should it handle the resizing? Does is pad and/or trim the edges? Or does it scale the image? If padding and trimming are used, does it do it at the center or topleft corner? If scaling is used, does it simply stretching it or do it proportionally? And which interpolation is being used? Nearest-neighbor, billinear, Lancoz, box, etc? If you really try to provide the good solution, you will end up to write a graphics editing program like GIMP or LazPaint. So TImage does not 'try' to handle the canvas resizing, it lets the programmer to implement the solution. ---------------------------------------------------------------------- Wilko500 · 2021-01-22 10:33 Thank you.  You have confirmed my own (inexperienced) thoughts.  I'll give your code a try as an interim solution.  I think I've arrived at a point where a simple port of existing logic/code from VB6 to FPC is not going to go as smoothly as I had hoped.  Time therefore to review the program logic, take stock and see if there is practical alternative that fits better into FPC framework. ---------------------------------------------------------------------- lucamar · 2021-01-22 11:03 Quote from: Handoko on January 22, 2021, 05:09:32 amThe issue happened because you resized the form. I believe for lightweight reason TImage does not 'renew' its canvas after being resized. You need create a new canvas to replace the old but because replacing the canvas is not allowed, so I replace the whole TImage directly. You don't need to do anything that complicated. What one should do is instead of drawing on the canvas of TImage, do it on the underlying graphic (for example, in the Bitmap property). If one does it that way TImage will happily adjust itself and/or the graphic to whatever properties you set for the control: Center, Proportional, Stretch, whatever. Seems I have to say this every time : TImage is *not* a "painting" control, like TPaintBox, but a "showing" one, meant to show an underlying graphic. Any graphic operation should be done in that graphic, not on the canvas of TImage. ---------------------------------------------------------------------- Wilko500 · 2021-01-23 01:37 Just out of interest I was having a look at bitmap and I discovered that I can achieve my needs by adding the following lines after dynamic creation of form and before drawing to it.  The two constants can be taken from the form width/height properties. The TImage.align is set t o alClient.  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 frm.Image1. Picture.Bitmap.Width:=600;frm.Image1.Picture.Bitmap.Height:=1581;frm.I mage1.Canvas.FillRect(frm.image1.BoundsRect); ---------------------------------------------------------------------- Handoko · 2021-01-23 03:18 Yes, that should work. I hadn't thought about it. ---------------------------------------------------------------------- lucamar · 2021-01-23 03:40 Rather than constants I would get the bitmap width and height from the TImage size and make sure the image has its Stretch property to True but otherwise, yes, that's what I meant ---------------------------------------------------------------------- Wilko500 · 2021-01-23 10:07 QuoteRather than constants I would get the bitmap width and height from the TImage size and make sure the image has its Stretch property to True but otherwise, yes, that's what I meantGood point, I was get them from the form, thank you.