几年来我一直在使用 GR32 库,持有一个不再维护的旧兼容单元 GR32_PolygonsOld。在某些时候,他们对 Polygons 单元进行了大量修改,并且有些东西不再存在,例如 TAntaliasMode 和 TPolygon32,但从来没有任何文档说明如何将旧代码迁移到新的过程和类。
如何将我的旧代码转换为使用 2.0.0 Alpha 及更高版本的新方法?
旧代码:(新代码不应使用不再属于其存储库的单元 GR32_PolygonsOld,而应使用 GR32_Polygons)
GR32官方库:https
://github.com/graphics32/graphics32
旧单元:https ://github.com/graphicsmagicteam/graphicsmagic/blob/master/externals/Graphics32_3rd_Party/GR32_PolygonsOld.pas
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
GR32, GR32_PolygonsOld;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure b32DoRectangle(bitmap: TBitmap32; Coords: TRect; Color: TColor32; AA: Boolean; AAMode: TAntiAliasMode);
begin
With TPolygon32.Create do begin
Antialiased := AA;
if AA then AntialiasMode := AAMode;
Add(GR32.FixedPoint(Coords.Left,Coords.Top));
Add(GR32.FixedPoint(Coords.Right,Coords.Top));
Add(GR32.FixedPoint(Coords.Right,Coords.Bottom));
Add(GR32.FixedPoint(Coords.Left,Coords.Bottom));
DrawFill(bitmap,Color);
Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var b32: TBitmap32;
begin
b32 := TBitmap32.Create;
b32.Width := 200;
b32.Height := 200;
b32.Clear(clWhite32);
b32DoRectangle(b32, Rect(20,20,70,70), SetAlpha(clRed32, 20), True, am8times);
b32.DrawTo(Image1.Canvas.Handle, 0,0);
b32.Free;
end;
end.
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 397
ClientWidth = 838
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 32
Top = 32
Width = 305
Height = 209
end
end