Re: [Lazarus] TAChart with transparent background
The image is a 30KB png, not much. It is smaller than the area, so it gets actually stretched. Can I use Draw instead of StretchDraw if I make the image exactly the size I need? I can force the form size. I think that tens of milliseconds can be actually relevant, because I am plotting data received (and processed) every 50ms from a serial port. R# 2014-09-16 0:07 GMT+02:00 Werner Pamler : > I added some simple time measuring code (using GetTickCount) to the > background image tutorial to see the speed loss that you mention: Without > the backgrounds (Lazarus logo and gradient) the GetTickCount reports 0 ms > between the OnBeforeDrawBackground and OnAfterPaint events, while with the > backgrounds it reports 16 ms, sometimes 0 ms. Replacing the StretchDraw by > a simple Draw in the painting of the logo, brings down the time also to 0. > Therefore I'd guess that the background painting is not perceivable unless > you squeeze a 20 mega-pixel photo into the chart area or load the image > during the painting event. > > What exactly are you doing? > > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TAChart with transparent background
Though really late, I can confirm that the solution is working fine. I still have to add some profiling code to measure it, though with added background it seems perceivably slower even on a recent PC (core i5 vpro). Are BGRA or other backends known to be faster? thanks anyway for the help! R# 2014-09-04 1:08 GMT+02:00 Roberto P. : > Thank you very much. > I need a background image, therefore as soon as I am back at the office > I'll try your code. > Thank you again! > > R# > > > 2014-09-02 18:18 GMT+02:00 Werner Pamler : > >> It is not fully clear to me what you mean by "a chart with transparent >> background". Do you want to see the form underneath the chart? I fear this >> is not easily possible. Or do you want to have a background image in the >> chart? For the latter case this code is working fine with me: >> >> type >> TForm1 = class(TForm) >> Chart1: TChart; >> procedure Chart1BeforeDrawBackground(ASender: TChart; ACanvas: >> TCanvas; >> const ARect: TRect; var ADoDefaultDrawing: Boolean); >> procedure Chart1BeforeDrawBackWall(ASender: TChart; ACanvas: TCanvas; >> const ARect: TRect; var ADoDefaultDrawing: Boolean); >> procedure FormCreate(Sender: TObject); >> procedure FormDestroy(Sender: TObject); >> private >> { private declarations } >> FBackImage: TPicture; >> public >> { public declarations } >> end; >> >> procedure TForm1.Chart1BeforeDrawBackWall(ASender: TChart; ACanvas: >> TCanvas; >> const ARect: TRect; var ADoDefaultDrawing: Boolean); >> begin >> ADoDefaultDrawing := false; >> ACanvas.StretchDraw(ARect, FBackImage.Graphic); >> end; >> >> procedure TForm1.Chart1BeforeDrawBackground(ASender: TChart; ACanvas: >> TCanvas; >> const ARect: TRect; var ADoDefaultDrawing: Boolean); >> begin >> ACanvas.GradientFill(ARect, clSkyBlue, clWhite, gdVertical); >> ADoDefaultDrawing := false; >> end; >> >> procedure TForm1.FormCreate(Sender: TObject); >> begin >> FBackImage := TPicture.Create; >> FBackImage.LoadFromFile('C:\lazarus-svn\images\splash_logo.png'); >> // please adapt this path to your lazarus installation >> end; >> >> procedure TForm1.FormDestroy(Sender: TObject); >> begin >> FBackImage.Free; >> end; >> >> The basic idea is to assign a handler to the chart events >> OnBeforeDrawBackWall or OnBeforeDrawBackground and disable the default >> background painting by setting ADoDefaultDrawing to false. The first event >> replaces painting of the area enclosed by the chart's frame ("Back wall"), >> the other one replaces painting of the entire chart background. Above >> example paints the Lazarus splash-logo as BackWall and a gradient as >> background. >> >> Maybe I'll once write a tutorial on this topic... >> >> >> -- >> ___ >> Lazarus mailing list >> Lazarus@lists.lazarus.freepascal.org >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] TAChart with transparent background
Thank you very much. I need a background image, therefore as soon as I am back at the office I'll try your code. Thank you again! R# 2014-09-02 18:18 GMT+02:00 Werner Pamler : > It is not fully clear to me what you mean by "a chart with transparent > background". Do you want to see the form underneath the chart? I fear this > is not easily possible. Or do you want to have a background image in the > chart? For the latter case this code is working fine with me: > > type > TForm1 = class(TForm) > Chart1: TChart; > procedure Chart1BeforeDrawBackground(ASender: TChart; ACanvas: > TCanvas; > const ARect: TRect; var ADoDefaultDrawing: Boolean); > procedure Chart1BeforeDrawBackWall(ASender: TChart; ACanvas: TCanvas; > const ARect: TRect; var ADoDefaultDrawing: Boolean); > procedure FormCreate(Sender: TObject); > procedure FormDestroy(Sender: TObject); > private > { private declarations } > FBackImage: TPicture; > public > { public declarations } > end; > > procedure TForm1.Chart1BeforeDrawBackWall(ASender: TChart; ACanvas: > TCanvas; > const ARect: TRect; var ADoDefaultDrawing: Boolean); > begin > ADoDefaultDrawing := false; > ACanvas.StretchDraw(ARect, FBackImage.Graphic); > end; > > procedure TForm1.Chart1BeforeDrawBackground(ASender: TChart; ACanvas: > TCanvas; > const ARect: TRect; var ADoDefaultDrawing: Boolean); > begin > ACanvas.GradientFill(ARect, clSkyBlue, clWhite, gdVertical); > ADoDefaultDrawing := false; > end; > > procedure TForm1.FormCreate(Sender: TObject); > begin > FBackImage := TPicture.Create; > FBackImage.LoadFromFile('C:\lazarus-svn\images\splash_logo.png'); > // please adapt this path to your lazarus installation > end; > > procedure TForm1.FormDestroy(Sender: TObject); > begin > FBackImage.Free; > end; > > The basic idea is to assign a handler to the chart events > OnBeforeDrawBackWall or OnBeforeDrawBackground and disable the default > background painting by setting ADoDefaultDrawing to false. The first event > replaces painting of the area enclosed by the chart's frame ("Back wall"), > the other one replaces painting of the entire chart background. Above > example paints the Lazarus splash-logo as BackWall and a gradient as > background. > > Maybe I'll once write a tutorial on this topic... > > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus