[fpc-pascal] TFPCanvasDrawer and anti-alias.

silvioprog silvioprog at gmail.com
Tue Jan 29 03:19:14 CET 2013


2013/1/28 Leonardo M. Ramé <martinrame at yahoo.com>

> [...]
> Silvio, TAchart has a BGRABitmap backend mode, it creates great
> anti-aliased graphics (both lines and text). I didn't tested on CGI without
> linking against graphic libraries, I think it relies on TCanvas, so maybe
> it won't work, but it worth a try.
>
> Leonardo M. Ramé
> http://leonardorame.blogspot.com
>

It works fine (see result here: http://imagebin.org/244612) in Win32 with
this code:

program noguidemo;

{$mode objfpc}{$H+}

uses
  Interfaces,
  Classes,
  FPCanvas,
  FPImage,
  FPImgCanv,
  TATools,
  TAGraph,
  TASeries,
  TADrawerCanvas,
  TADrawUtils,
  BGRABitmap,
  TAChartUtils,
  TADrawerBGRA;

var
  chart: TChart;
  bs: TBarSeries;
  img: TBGRABitmap;
  d: IChartDrawer;
begin
  chart := TChart.Create(nil);
  chart.LeftAxis.Marks.LabelFont.Name := 'Arial';
  chart.LeftAxis.Marks.LabelFont.Size := 10;
  chart.LeftAxis.Marks.LabelFont.Orientation := 450;
  chart.LeftAxis.Marks.Frame.Visible := True;
  chart.LeftAxis.Marks.Frame.Style := psSolid;
  chart.LeftAxis.Marks.Frame.FPColor := colBlack;
  chart.LeftAxis.Grid.FPColor := colDkGray;
  chart.BottomAxis.Marks.Visible := False;
  chart.BottomAxis.Grid.FPColor := colDkGray;
  chart.Color := $FFA0A0;
  chart.BackColor := $FFFFFF;
  bs := TBarSeries.Create(nil);
  chart.AddSeries(bs);
  bs.AddXY(1, 10);
  bs.AddXY(2, 7);
  bs.AddXY(3, 8);
  img := TBGRABitmap.Create(chart.Width, chart.Height);
  d := TBGRABitmapDrawer.Create(img);
  img.CanvasBGRA.Font.Antialiasing := true;
  img.CanvasBGRA.Font.Name := 'Arial';
  d.DoGetFontOrientation := @CanvasGetFontOrientationFunc;
  chart.Draw(d, Rect(0, 0, chart.Width, chart.Height));
  img.SaveToFile('test.png');
  img.Free;
  bs.Free;
  chart.Free;
end.

But, with NoGUI, the error is:

C:\Users\silvioprog\Desktop\nogui>noguidemo.exe
TRasterImage.BitmapHandleNeeded: Unable to create handles, using default
[FORMS.PP] ExceptionOccurred
  Sender=EInvalidOperation
  Exception=Canvas does not allow drawing
  Stack trace:
  $004951D4  TCANVAS__REQUIREDSTATE,  line 1672 of ./include/canvas.inc
  $004953F0  TCANVAS__TEXTEXTENT,  line 1731 of ./include/canvas.inc
  $0060A29F  GETFONTHEIGHTSIGN,  line 236 of bgratext.pas
  $005BCEFA  TBGRADEFAULTBITMAP__INIT,  line 1684 of bgradefaultbitmap.pas
  $005B9DF6  TBGRADEFAULTBITMAP__CREATE,  line 732 of bgradefaultbitmap.pas
  $00401B91  main,  line 43 of noguidemo.lpr
TApplication.HandleException Canvas does not allow drawing
  Stack trace:
  $004951D4  TCANVAS__REQUIREDSTATE,  line 1672 of ./include/canvas.inc
  $004953F0  TCANVAS__TEXTEXTENT,  line 1731 of ./include/canvas.inc
  $0060A29F  GETFONTHEIGHTSIGN,  line 236 of bgratext.pas
  $005BCEFA  TBGRADEFAULTBITMAP__INIT,  line 1684 of bgradefaultbitmap.pas
  $005B9DF6  TBGRADEFAULTBITMAP__CREATE,  line 732 of bgradefaultbitmap.pas
  $00401B91  main,  line 43 of noguidemo.lpr
Exception at 004951D4: EInvalidOperation:
Canvas does not allow drawing.

C:\Users\silvioprog\Desktop\nogui>

:(

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130129/f6b2d5e2/attachment.html>


More information about the fpc-pascal mailing list