Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Gradient inkl. Gloweffekt zeichnen (https://www.delphipraxis.net/153601-gradient-inkl-gloweffekt-zeichnen.html)

stOrM 10. Aug 2010 04:42

Gradient inkl. Gloweffekt zeichnen
 
Liste der Anhänge anzeigen (Anzahl: 2)
Ja Moin,
ich hab da grad ein Problem und frag mich wie man das lösen könnte.
Es geht mir darum einen Gradient zu zeichnen soweit so gut dank der GradientFill Funktion auch nicht weiter tragisch.

Nun hatte ich noch die Idee an der oberen Kante des 1. Gradients noch eine art Gloweffekt zu malen mit einem weiteren Gradient der in etwa 9 Pixel hoch sein sollte der fängt weiss an und geht nach Transparent.

Ich wusste mir im Moment nicht anders zu helfen als das ich den weiss nach transparenten Gradient in Photoshop erstelle und das Ding dann als PNG speichere. Später mal ich den dann einfach über den ersten Gradient in etwa so (oder bzw. genau so :mrgreen: )


Delphi-Quellcode:
FPng.Draw(Pnl.Canvas, R);


Nun ist zwar ned hübsch aber funzt soweit. Aber kann man so einen Gradient nicht von Hand erstellen und über den ersten zeichnen :?:

Das Problem scheint irgendwie zu sein das die GradientFill Funktion zwar über nen Alpha verfügt, jedoch nicht genutzt wird :shock:

Ich hab mal 2 Beispiele mit drangepappt damit man sieht wovon ich hier eigentlich rede. Einmal ohne Glow einmal mit Gloweffekt...

Wäre schön wenn jemand dafür eine Lösung aus dem Hut zaubern kann, weil auch wenn es so klappt, so ganz glücklich bin ich damit nicht wirklich :(

Viele Grüsse
s!

turboPASCAL 10. Aug 2010 11:12

AW: Gradient inkl. Gloweffekt zeichnen
 
Liste der Anhänge anzeigen (Anzahl: 2)
GradientFill kann auch Transparents. ;)

Beispiel:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  bf: _BLENDFUNCTION = (
    BlendOp: AC_SRC_OVER;
    BlendFlags: 0;
    SourceConstantAlpha: 255;
    AlphaFormat: AC_SRC_ALPHA);

type
  TGFillMode = (GRADIENT_FILL_RECT_H, GRADIENT_FILL_RECT_V);

function GradientFill(DC: HDC; pTriVertex: Pointer; dwNumVertex: DWORD;
  pMesh: Pointer; dwNumMesh, dwMode: DWORD): BOOL; stdcall;
  external 'msimg32.dll' name 'GradientFill';

function GradientFill4c(DC: HDC; fillRect: TRect; Col: array of COLORREF; FillMode: TGFillMode): Boolean;
type
  _TTRIVERTEX = packed record
    X, Y: DWORD;
    Red, Green, Blue, Alpha: Word;
  end;
var
  tv: array[0..3] of _TTRIVERTEX;
  gr: array[0..1] of GRADIENT_RECT;
  i: integer;
begin
  if length(col) = 4 then
  begin
    // fillmode direction
    gr[0].UpperLeft := 0;
    gr[0].LowerRight := 1;
    gr[1].UpperLeft := 2;
    gr[1].LowerRight := 3;

    ZeroMemory(@tv, sizeof(tv));
    // eckpunkte festlegen
    if FillMode = GRADIENT_FILL_RECT_V then
    begin
      tv[0].x := fillRect.Left;
      tv[0].y := fillRect.Top;
      tv[1].x := fillRect.Right;
      tv[1].y := (fillRect.Top + fillRect.Bottom) div 2;

      tv[2].x := fillRect.Left;
      tv[2].y := (fillRect.Top + fillRect.Bottom) div 2;
      tv[3].x := fillRect.Right;
      tv[3].y := fillRect.Bottom;
    end
    else
    begin
      tv[0].x := fillRect.Left;
      tv[0].y := fillRect.Top;
      tv[1].x := (fillRect.Left + fillRect.Right) div 2;
      tv[1].y := fillRect.Bottom;

      tv[2].x := (fillRect.Left + fillRect.Right) div 2;
      tv[2].y := fillRect.Top;
      tv[3].x := fillRect.Right;
      tv[3].y := fillRect.Bottom;
    end;

    for i := 0 to high(Col) do
    begin
      tv[i].Red  := BYTE(col[i]) shl 8;          // get Color's and Byteswap for Color-Word
      tv[i].Green := BYTE(col[i] shr 8) shl 8;
      tv[i].Blue := BYTE(col[i] shr 16) shl 8;
      tv[i].Alpha := BYTE(col[i] shr 24) shl 8;
    end;

    Result := GradientFill(DC, @tv, length(tv), @gr, length(gr), DWORD(FillMode));
  end
  else
    Result := False;
end;


// Note that GradientFill does not use the Alpha member of the TRIVERTEX structure.
// To use GradientFill with transparency, call GradientFill and then call AlphaBlend
// with the desired values for the alpha channel of each vertex.

function GradientFill4cT(DC: HDC; fillRect: TRect; Col: array of COLORREF; FillMode: TGFillMode; bf: _BLENDFUNCTION): Boolean;
var
  w, h: integer;
  hBmpDC: HDC;
  hBmp: HBITMAP;
begin

  w := fillRect.Right - fillRect.Left;
  h := fillRect.Bottom - fillRect.Top;

  hBmpDC := CreateCompatibleDC(DC);         //todo: Achtung: keine Fehlerprüfung !
  hBmp := CreateBitmap(w, h, 1, 32, nil);
  SelectObject(hBmpDC, hBmp);

  Result := GradientFill4c(hBmpDC, RECT(0, 0, w, h), Col, FillMode);

  with fillRect do
    Result := Result and Windows.AlphaBlend(
      DC,
      Left, Top, Right - Left, Bottom - Top,
      hBmpDC,
      0, 0, w, h,
      bf);

  DeleteObject(hBmp);
  DeleteDC(hBmpDC);
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  pr: TRect;
begin
  pr := RECT(20,20,160,180);
  GradientFill4c(Self.Canvas.Handle, pr, [$000000FF, $008080FF, $000000FF, $000000C8], GRADIENT_FILL_RECT_V);
  OffSetRect(pr, 50, 50);
  GradientFill4c(Self.Canvas.Handle, pr, [$00FFFFFF, $00FFFFFF, $00FFFFFF, $00C00000], GRADIENT_FILL_RECT_H);

  // GradientFill with transparency

  OffSetRect(pr, 50, 50);
  GradientFill4cT(Self.Canvas.Handle, pr,[$FF0000FF, $A08080FF, $B00000FF, $FF0000C8], GRADIENT_FILL_RECT_V, bf);
end;

end.

stOrM 10. Aug 2010 16:36

AW: Gradient inkl. Gloweffekt zeichnen
 
Boh ich freu mir grad nen Ast DANNNNNKEEEE! :thumb:

Viele Grüsse
Marc


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:15 Uhr.

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