Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#5

Re: Canvas transparente linien zeichnen ?!

  Alt 18. Mai 2009, 06:57
Ok, keine Linie. Aaber ein Rechteck, was eigentlich auch eine "dicke" Linie ist, das Prinzip ist das selbe.

Wenn es um Horizontale oder Vertikale Linie(n) geht ist es einfach.
Will man nun Diagonele Linie(n) wird es komplexer da man diede selbst berechnen muss.

Delphi-Quellcode:
//////////////////////////////////////////////////////////////////////////////
// Fillrect per Bitmap & Scanline (unoptimiert)
// - mittelschnell
// - medium rechenrechenintensiv
// - "T" for Transparent & "S" for Scanlinie
// by turboPASCAL aka MatthiasG.
procedure FillrectTS(Bitmap: TBitmap; X1, Y1, X2, Y2: integer; Color: TColor32);
type
  TRGBA = Record
    R,G,B,A: Byte;
  end;
  TRGBQuadArray = array[WORD] of TRGBA;
  pRGBQuadArray = ^TRGBQuadArray;
var
  p: pRGBQuadArray;
  x,y: integer;
  h1,h2: single;
begin

  if (X2 > X1) and (Y2 > Y1) then
    with Bitmap.Canvas do
    begin
      if X1 < ClipRect.Left then X1 := ClipRect.Left;
      if Y1 < ClipRect.Top then Y1 := ClipRect.Top;
      if X2 > ClipRect.Right then X2 := ClipRect.Right;
      if Y2 > ClipRect.Bottom then Y2 := ClipRect.Bottom;
    end;

  if Bitmap.PixelFormat <> pf32Bit then
    Bitmap.PixelFormat := pf32Bit;

  h1:= GetAValue(Color) / 255;
  h2:= 1 - h1;

  for y := y1 to y2 - 1 do
  begin
    p := Bitmap.Scanline[y];
    for x := x1 to x2 - 1 do
    begin
      p[x].R := BYTE( round( h1 * p[x].R + h2 * GetRValue(Color) ) );
      p[x].G := BYTE( round( h1 * p[x].G + h2 * GetGValue(Color) ) );
      p[x].B := BYTE( round( h1 * p[x].B + h2 * GetBValue(Color) ) );
    end;
  end;
end;
Angehängte Dateien
Dateityp: zip trcolorgdi.source_203.zip (63,2 KB, 22x aufgerufen)
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat