Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Gradient mit TBitmap32 (https://www.delphipraxis.net/187393-gradient-mit-tbitmap32.html)

Wishmaster 25. Nov 2015 12:44

Gradient mit TBitmap32
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi.
ich arbeite an einigen Komponenten. dazu benutze ich die Lib. graphics32
nun habe ich einige probleme mit Gradient's, genauer gesagt Circular Gradient
der Gradient muss in ein bestimmten rammen Reinpassen etwa in einen Rectangle, RoundRect, Round

das mit Vertical/Horizontal Gradient funzt,..... nur der rest.



Delphi-Quellcode:

function MakeRectangle(const Rec: TFloatRect): TArrayOfFloatPoint;
var
  FRec : TFloatRect;
begin
  FRec.Left:= 0;
  FRec.Top:= 0;
  FRec.Right:= Rec.Right;
  FRec.Bottom:= Rec.Bottom;
  Result:= Rectangle(FRec);
end;


function MakeRoundRect(Radius : TFloat; Rec: TFloatRect): TArrayOfFloatPoint;
var
 FRec : TFloatRect;
begin
  FRec.Left:= 0;
  FRec.Top:= 0;
  FRec.Right:= Rec.Right;
  FRec.Bottom:= Rec.Bottom;
  Result:= RoundRect(FRec, Radius);
end;


procedure Gradient_Fill_Vertical(Buffer : TBitmap32; Rec: TRect; RoundRect, Mirror : Boolean;
 ColorFrom, ColorTo, MirrorFrom, MirrorTo : TColor; MirrorFromPos, MirrorToPos : TFloat);
var
 GradFiller : TLinearGradientPolygonFiller;
 Polys: TArrayOfArrayOfFloatPoint;
 OutlinePolygon: TArrayOfFloatPoint;
 FloatRect : TFloatRect;

procedure AddPolygon(const Pts: TArrayOfFloatPoint);
begin
 with TClipper.Create do
  try
   Add(Polys, ptSubject);
   Add(Pts, ptClip);
   Execute(ctUnion, Polys, pftNonZero);
  finally
   Free;
  end;
end;

begin

   FloatRect.Left:= Rec.Left;
   FloatRect.Top:= Rec.Top;
   FloatRect.Right:= Rec.Right;
   FloatRect.Bottom:= Rec.Height;

  if RoundRect then
   OutlinePolygon:= MakeRoundRect(8.0, FloatRect)
  else
   OutlinePolygon:= MakeRectangle(FloatRect);
   AddPolygon(OutlinePolygon);

   GradFiller := TLinearGradientPolygonFiller.Create;
  try
    GradFiller.SetPoints(FloatPoint(0, FloatRect.Top), FloatPoint(0, FloatRect.Bottom));

   if not Mirror then
    begin
     GradFiller.Gradient.StartColor := Color32(ColorFrom);
     GradFiller.Gradient.EndColor  := Color32(ColorTo);
    end else
    begin
     GradFiller.Gradient.StartColor := Color32(ColorFrom);
     GradFiller.Gradient.AddColorStop(MirrorFromPos, Color32(MirrorFrom));
     GradFiller.Gradient.AddColorStop(MirrorToPos, Color32(MirrorTo));
     GradFiller.Gradient.EndColor  := Color32(ColorTo);
    end;


    PolyPolygonFS(Buffer, Polys, GradFiller, pfWinding);

  finally
   GradFiller.Free;
   Setlength(Polys, 0);
  end;

end;

Jens01 25. Nov 2015 14:47

AW: Gradient mit TBitmap32
 
Wo ist genau Dein Problem?

Blup 26. Nov 2015 08:57

AW: Gradient mit TBitmap32
 
Ist das nicht richtiger?
[delphi]
GradFiller.SetPoints(FloatPoint(FloatRect.Left, FloatRect.Top), FloatPoint(FloatRect.Right, FloatRect.Bottom));
[delphi]


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:37 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz