Having Problem with GradientFill... lazarus / 39-Graphics ---------------------------------------------------------------------- Josh · 2018-05-17 11:28 Hi Banging head against wall for last few hours, and now my head is hurting.. I have minimized the code below; which exhibits the same problem. If I create a form place a timage and trackbar (set max to image height) on it and add the code below to trackbar change. When I move the trackbar I get a gradient fill on the image, as expected. Now if I add the same code to my existing project, then it does not work, if i use the rectangle function then It draws.. Anyone had a similar problem, I have checked that the calls are calling the same unit calls; ie thats why I explicitly added classes. prefix. I suspect if you test the code it will work.. This is expected... Thanks 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.TrackBar1Change(Sender: TObject);Var TempBmp:TBitmap;  image_height:integer;      image_width:integer;begin  image_width:=Image1.Width;  image_height:=Image1.Height;  TempBmp:=TBitmap.Create;  TempBmp.Width:=image_width;  TempBmp.Height:=image_height;  TempBmp.Canvas.Pen.Style:=psSolid;  TempBmp.Canvas.pen.Width:=0; // TempBmp.canvas.Rectangle(0,0,image_width,TrackBar1.Position);  TempBmp .Canvas.GradientFill(classes.rect(0,0,image_width,TrackBar1.Position), clBlue,clGreen,gdVertical);  Image1.Picture.Bitmap:=tempbmp;  TempBmp.Free;end; ---------------------------------------------------------------------- Thaddy · 2018-05-17 11:35 It probably needs an explicit repaint message, so add a Application.ProcessMessages or an otherwise forced paint. ---------------------------------------------------------------------- Josh · 2018-05-17 11:42 Hi Thaddy, Thanks for your response, I have tried Image.refresh and application.processmessages. But this has no effect. The rectangle draws a solid block to canvas and updates without the force update. It's as though the fillrectangle is not doing anything.. I have even modified it so half is solid and half is gradient; and only the solid part is drawn. Like I say its odd, as new project with exactly the same code works; but not in existing project; wondering if exiting project unit declaration could be interferring with this. I may try creating a seperate unit based on new project uses declaration and add the code to that.. Maybe you never know. ---------------------------------------------------------------------- Handoko · 2018-05-17 12:13 Yes, your code works. It works correctly without showing any issue, tested on my Linux computer. So can you provide us the code that can 'really' show the issue? ---------------------------------------------------------------------- Josh · 2018-05-17 12:28 Hi Handoko, Thanks for checking. Unfortuantely I cant give the code for when its not working, as it's a very large project and has propritery code. When the application is doing loads of work, I have various indication of what it is doing at a given time, these were done with rectangle and worked fine, just changing it to fillgradient then I have no indication, taking out this  code and placing in new project using a trackbar to simulate the progress then all is fine. At the moment I am trying to work out why. ---------------------------------------------------------------------- balazsszekely · 2018-05-17 12:34 The next logical step is to save the bmp to a file: 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 TempBmp.Can vas.GradientFill(classes.rect(0,0,image_width,TrackBar1.Position),clBl ue,clGreen,gdVertical);TempBmp.SaveToFile('thepath'); Check the saved bmp. If is empty insert a Canvas.Changed after the gradient draw. 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 TempBmp.Canvas.GradientFill(classes.rect(0,0,image_width,TrackB ar1.Position),clBlue,clGreen,gdVertical);TempBmp.Canvas.Changed; ---------------------------------------------------------------------- Handoko · 2018-05-17 13:15 @josh I understand, for some reasons you're not willing to publicize the code. But can you write a demo showing that issue? I personally believe the bug is not in the code that you just provided. If I have the case like yours, I will do things like these: 01. Make a backup of the project 02. Remove one unrelated form/unit 03. Compile and run 04. Go to step #02, until only the form and necessary units that showing the issue 05. Remove one unnecessary component on the form 06. Compile and run 07. Go to step #05, until only the necessary component that showing the issue Now, you get the 'fat loss' version of the project that can show the issue. So you can continue: 08. Try to compile and run the code on different Lazarus/FPC versions 09. Try to compile and run the code on different OSes If the problem is not reproducible on step #08 or #09, then it should be widgetset/OS-dependent/compiler's issue. But if the problem still exists, then I will one-by-one replace the forms/units by writing the new ones. Because by regenerating them, I may find some typing or logic mistake that I previous made on those old code. But if still can't find the answers, I will set lots of debug things to see where goes wrong. Bugs can hide in anywhere of the code. Debugging a big project is difficult, so to make it easier I usually will do the 'fat loss' first. ---------------------------------------------------------------------- Josh · 2018-05-17 13:41 @getmem Thanks for some diag tips, i added in the savetofile, and this shows that it is NOT creating the gradient on the canvas, i added in the canvas.changed before the savetofile and it still does not add the gradient.  using Rectangle fill then all images generated are complete. So perplexed, as one of my components in this project uses the GradientFill ( no special graphics library) to generate control canvases and these work fine. @handoko The project is a single form project; so this does help diagnose; I will strip it down and start removing components and libraries; incase they are interferring. It does use a fair amount of bgrabitmap and bgracontrols; Might take some time to elimiante, but hopefully can track down what is casuing it. ---------------------------------------------------------------------- balazsszekely · 2018-05-17 13:51 Then you overwrite somehow the drawing or you're writing to the wrong canvas. Unfortunately I cannot help you without the code. Alternatively you can put a breakpoint to each place where you write to the image and use the Call Stack window to trace back the code. ---------------------------------------------------------------------- Josh · 2018-05-18 01:48 Hi I have created a sampple app; this routine is writing to timage canvas, and works for rectangle but not for gradientfill I suspect its me and something obvious. Updated zip file 4:05am ---------------------------------------------------------------------- balazsszekely · 2018-05-18 04:25 QuoteI have created a sampple app; this routine is writing to timage canvas, and works for rectangle but not for gradientfillPlease test attached project. ---------------------------------------------------------------------- Handoko · 2018-05-18 05:15 Yes, GetMem's code works correctly. So the culprit is (it is on line #48): 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     canvas.Pen.Style:=psClear; Simply remove that line in josh's code, it works correctly on my test. ---------------------------------------------------------------------- Josh · 2018-05-18 18:14 Hi Getman and Handoko, Thanks for debugging my code and solving my Bad Head I would not have thought that a pen.style would effect how a GradientFill is drawn; or not in this case. Again thanks