this slowpoke moves

Draw Gradient to Image

Beispiel 1:
procedure DrawGradient(ACanvas: TCanvas; Rect: TRect;
  Horicontal: Boolean; Colors: array of TColor);
type
  RGBArray = array[0..2] of Byte;
var
  x, y, z, stelle, mx, bis, faColorsh, mass: Integer;
  Faktor: double;
  A: RGBArray;
  B: array of RGBArray;
  merkw: integer;
  merks: TPenStyle;
  merkp: TColor;
begin
  mx := High(Colors);
  if mx > 0 then
  begin
    if Horicontal then
      mass := Rect.Right - Rect.Left
    else
      mass := Rect.Bottom - Rect.Top;
    SetLength(b, mx + 1);
    for x := 0 to mx do
    begin
      Colors[x] := ColorToRGB(Colors[x]);
      b[x][0] := GetRValue(Colors[x]);
      b[x][1] := GetGValue(Colors[x]);
      b[x][2] := GetBValue(Colors[x]);
    end;
    merkw := ACanvas.Pen.Width;
    merks := ACanvas.Pen.Style;
    merkp := ACanvas.Pen.Color;
    ACanvas.Pen.Width := 1;
    ACanvas.Pen.Style := psSolid;
    faColorsh := Round(mass / mx);
    for y := 0 to mx - 1 do
    begin
      if y = mx - 1 then
        bis := mass - y * faColorsh - 1
      else
        bis := faColorsh;
      for x := 0 to bis do
      begin
        Stelle := x + y * faColorsh;
        faktor := x / bis;
        for z := 0 to 3 do
          a[z] := Trunc(b[y][z] + ((b[y + 1][z] - b[y][z]) * Faktor));
        ACanvas.Pen.Color := RGB(a[0], a[1], a[2]);
        if Horicontal then
        begin
          ACanvas.MoveTo(Rect.Left + Stelle, Rect.Top);
          ACanvas.LineTo(Rect.Left + Stelle, Rect.Bottom);
        end
        else
        begin
          ACanvas.MoveTo(Rect.Left, Rect.Top + Stelle);
          ACanvas.LineTo(Rect.Right, Rect.Top + Stelle);
        end;
      end;
    end;
    b := nil;
    ACanvas.Pen.Width := merkw;
    ACanvas.Pen.Style := merks;
    ACanvas.Pen.Color := merkp;
  end
  else
    raise EMathError.Create('Es müssen mindestens zwei Farben angegeben werden.');
end;
Beispiel Horizontal :
procedure TForm1.Button1Click(Sender: TObject);
begin
  DrawGradient(Image1.Canvas, Rect(0, 00, 200, 200), False, [clRed, $00FFA9B4]);
end;
Beispiel Vertical :
procedure TForm1.Button1Click(Sender: TObject);
begin
  DrawGradient(Image1.Canvas, GetClientRect, True, [121351, clred, clblue, clWhite]);
end;
Beispiel mit vielen Farben :
procedure TForm1.Button1Click(Sender: TObject);
begin
  DrawGradient(Image1.Canvas, GetClientRect, True, [ColorDialog1.Color, clRed, clBlack, clWhite, clBlack, clred]);
end;
Beispiel 2:
procedure TForm1.FormCreate(Sender: TObject);
Var
  C, R, H, W : Integer;
  Step : Real;
begin
   H:=Image1.Height;
   W:=Image1.Width;
   Step:=255/H;
   C := 0;
   For R := 0 To H Do
   Begin
     Image1.Canvas.Pen.Color := RGB(255,255,255-C);
     Image1.Canvas.MoveTo(0,R);
     Image1.Canvas.LineTo(W,R);
     C:=Round(R*Step);
   End;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate