[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=E9 <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 witho=
ut
> linking against graphic libraries, I think it relies on TCanvas, so maybe
> it won't work, but it worth a try.
>
> Leonardo M. Ram=E9
> 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 :=3D TChart.Create(nil);
  chart.LeftAxis.Marks.LabelFont.Name :=3D 'Arial';
  chart.LeftAxis.Marks.LabelFont.Size :=3D 10;
  chart.LeftAxis.Marks.LabelFont.Orientation :=3D 450;
  chart.LeftAxis.Marks.Frame.Visible :=3D True;
  chart.LeftAxis.Marks.Frame.Style :=3D psSolid;
  chart.LeftAxis.Marks.Frame.FPColor :=3D colBlack;
  chart.LeftAxis.Grid.FPColor :=3D colDkGray;
  chart.BottomAxis.Marks.Visible :=3D False;
  chart.BottomAxis.Grid.FPColor :=3D colDkGray;
  chart.Color :=3D $FFA0A0;
  chart.BackColor :=3D $FFFFFF;
  bs :=3D TBarSeries.Create(nil);
  chart.AddSeries(bs);
  bs.AddXY(1, 10);
  bs.AddXY(2, 7);
  bs.AddXY(3, 8);
  img :=3D TBGRABitmap.Create(chart.Width, chart.Height);
  d :=3D TBGRABitmapDrawer.Create(img);
  img.CanvasBGRA.Font.Antialiasing :=3D true;
  img.CanvasBGRA.Font.Name :=3D 'Arial';
  d.DoGetFontOrientation :=3D @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=3DEInvalidOperation
  Exception=3DCanvas 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=E9cio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freepascal.org/lists/fpc-pascal/attachments/20130129/f6b2=
d5e2/attachment.htm


More information about the fpc-pascal mailing list