BGRABitmap图像操作11:渐变生成加上色彩,让她更漂亮

来源:互联网 发布:python爬虫有什么用 编辑:程序博客网 时间:2024/05/22 05:21




unit Unit1;{$mode objfpc}{$H+}interfaceuses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  BGRABitmap, BGRABitmapTypes, BGRAGradientScanner, BGRATransform;type  { TBGRAMultiplyScanner }  TBGRAMultiplyScanner = class(TBGRACustomScanner)    function ScanAt(X, Y: Single): TBGRAPixel; override;  end;type  { TForm1 }  TForm1 = class(TForm)    procedure FormPaint(Sender: TObject);  private    { private declarations }  public    { public declarations }  end;var  Form1: TForm1;implementation{$R *.lfm}{ TForm1 }function TBGRAMultiplyScanner.ScanAt(X, Y: Single): TBGRAPixel;  function cycle512(value: integer): integer; inline;  begin    result := value and 511;    if result >= 256 then result := 511-result;  end;var  mul: integer;begin  mul := round(x*y);  result := BGRA(cycle512(round(x*10)),cycle512(mul),cycle512(round(y*10)),255);end;procedure TForm1.FormPaint(Sender: TObject);var image: TBGRABitmap;    grad: TBGRAMultiplyScanner;    affine: TBGRAAffineScannerTransform;begin  image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );  grad := TBGRAMultiplyScanner.Create;  affine := TBGRAAffineScannerTransform.Create(grad);  affine.Scale(6,4);  affine.Translate(ClientWidth/2, ClientHeight/2);  image.Fill(affine);  affine.free;  grad.free;  image.Draw(Canvas,0,0,True);  image.free;end;end.



0 0