AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Windows.GradientFill
Thema durchsuchen
Ansicht
Themen-Optionen

Windows.GradientFill

Ein Thema von Neutral General · begonnen am 25. Okt 2006 · letzter Beitrag vom 15. Sep 2009
Antwort Antwort
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Windows.GradientFill

  Alt 25. Okt 2006, 12:08
Hi,

Habe gerade mal die Windows Unit durchgekramt aus Langeweile.. Bin auf ne Funktion namens GradientFill gestoßen. Macht die echt das was ich denke was sie macht? Naja egal. Ich will sie gerne mal ausprobieren. Aber ich weiß bei manchen Parametern nicht weiter:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var test: _TRIVERTEX;
begin
  test.x := 20;
  test.y := 50;
  test.Red := 100;
  test.Green := 50;
  test.Blue := 30;
  test.Alpha := 125;
  Windows.GradientFill(Canvas.Handle,ehm,{1},{2},{3},GRADIENT_FILL_TRIANGLE);
end;
1. NumVertex: Cardinal
2. Mesh: Pointer
3. NumMesh: Cardinal

Was bedeuten diese Parameter und was muss ich übergeben? Vorallem bei dem Pointer hab ich keine Ahnung was ich da Pointern soll... Ich hab mal irgendnen Schwachsinn übergeben da oder was nicht so Schwachsinniges aber es passiert einfach nie was. Es gibt auch keine AV...

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Windows.GradientFill

  Alt 25. Okt 2006, 12:16
Die Hilfe sagt mir:
Zitat von Delphi Hilfe:
GradientFill
The GradientFill function fills rectangle and triangle structures.

BOOL GradientFill(
HDC hdc, // handle to DC
PTRIVERTEX pVertex, // array of vertices
ULONG dwNumVertex, // number of vertices
PVOID pMesh, // array of gradients
ULONG dwNumMesh, // size of gradient array
ULONG dwMode // gradient fill mode
);
Parameters
hdc
[in] Handle to the destination device context.
pVertex
[in] Pointer to an array of TRIVERTEX structures that each define a triangle vertex.
dwNumVertex
[in] The number of vertices in pVertex.
pMesh
[in] Array of GRADIENT_TRIANGLE structures in triangle mode, or an array of GRADIENT_RECT structures in rectangle mode.
dwNumMesh
[in] The number of elements (triangles or rectangles) in pMesh.
dwMode
[in] Specifies gradient fill mode. This parameter can be one of the following values. Value Meaning
GRADIENT_FILL_RECT_H In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates the color from the left to right edge and fills the interior.
GRADIENT_FILL_RECT_V In this mode, two endpoints describe a rectangle. The rectangle is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates the color from the top to bottom edge and fills the interior.
GRADIENT_FILL_TRIANGLE In this mode, an array of TRIVERTEX structures is passed to GDI along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8-, 4-, and 1-bpp mode.


Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks
To add smooth shading to a triangle, call the GradientFill function with the three triangle endpoints. GDI will linearly interpolate and fill the triangle.

To add smooth shading to a rectangle, call GradientFill with the upper-left and lower-right coordinates of the rectangle. There are two shading modes used when drawing a rectangle. In horizontal mode, the rectangle is shaded from left-to-right. In vertical mode, the rectangle is shaded from top-to-bottom.

The GradientFill function uses a mesh method to specify the endpoints of the object to draw. All vertices are passed to GradientFill in the pVertex array. The pMesh parameter specifies how these vertices are connected to form an object. When filling a rectangle, pMesh points to an array of GRADIENT_RECT structures. Each GRADIENT_RECT structure specifies the index of two vertices in the pVertex array. These two vertices form the upper-left and lower-right boundary of one rectangle.

In the case of filling a triangle, pMesh points to an array of GRADIENT_TRIANGLE structures. Each GRADIENT_TRIANGLE structure specifies the index of three vertices in the pVertex array. These three vertices form one triangle.

To simplify hardware acceleration, this routine is not required to be pixel-perfect in the triangle interior.

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.

For more information, see Smooth Shading, Drawing a Shaded Triangle, and Drawing a Shaded Rectangle.

Requirements
Windows NT/2000/XP: Included in Windows 2000 or later.
Windows 95/98/Me: Included in Windows 98 or later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Included as a resource in Msimg32.dll.

See Also
Bitmaps Overview, Bitmap Functions, EMRGRADIENTFILL, GRADIENT_RECT, GRADIENT_TRIANGLE, TRIVERTEX


--------------------------------------------------------------------------------

© 2002 Microsoft Corporation. All rights reserved.

Requirements
Windows NT/2000/XP: Included in Windows 2000 or later.
Windows 95/98/Me: Included in Windows 98 or later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Included as a resource in Msimg32.dll.
See Also
Bitmaps Overview, Bitmap Functions, EMRGRADIENTFILL, GRADIENT_RECT, GRADIENT_TRIANGLE, TRIVERTEX


--------------------------------------------------------------------------------

© 2002 Microsoft Corporation. All rights reserved.
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

Re: Windows.GradientFill

  Alt 25. Okt 2006, 12:29
Ok danke... Naja meine Hilfe hat mir komischerweise nichts dazu gesagt ....

STOPP!

Zitat:
[in] Pointer to an array of TRIVERTEX structures that each define a triangle vertex.
dwNumVertex
Bei mir wird nur ein einzelnes TRIVERTEX erwartet und akzeptiert o.O
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Benutzerbild von Flocke
Flocke

Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#4

Re: Windows.GradientFill

  Alt 25. Okt 2006, 16:01
Ist halt (wie so viele Dinge) von Borland nicht korrekt deklariert worden. Nimm ein Array von TTriVertex Elementen und übergib das erste als Var-Parameter.
Volker
Besucht meine Garage
Aktuell: RtfLabel 1.3d, PrintToFile 1.4
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

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

Re: Windows.GradientFill

  Alt 25. Nov 2008, 14:05
Ich habe mir grad eine Funktion gebastelt:

Delphi-Quellcode:
var
  _GradientFill: function(DC: HDC; pTriVertex: Pointer; dwNumVertex: DWORD;
  pMesh: Pointer; dwNumMesh, dwMode: DWORD): DWORD; stdcall; { external in "msimg32.dll" }

type
  TFillMode = GRADIENT_FILL_RECT_H..GRADIENT_FILL_RECT_V;

function wGradientFill(DC: HDC; fillRect: TRect; startColor, endColor: COLORREF; FillMode: TFillMode): Boolean;
type
  _TTRIVERTEX = packed record
    X, Y: DWORD;
    Red, Green, Blue, Alpha: Word;
  end;
var
  tv: array [0..1] of _TTRIVERTEX;
  gr: GRADIENT_RECT;
  hLib: THandle;
begin
  // -------------------------------------------------------------------------
  // sollte global aufgerufen werden zB. in FormCreate
  // an sonsten wird das laden und freigeben unnötig oft aufgerufen
  hLib := LoadLibrary('MSIMG32.DLL');
  if hLib <> 0 then
    @_GradientFill := GetProcAddress(hLib, 'GradientFill');
  // -------------------------------------------------------------------------

  if @_GradientFill <> nil then
  begin
    // fillmode direction
    gr.UpperLeft := 0;
    gr.LowerRight := 1;

    // eckpunkte festlegen
    tv[0].x := fillRect.Left;
    tv[0].y := fillRect.Top;
    tv[1].x := fillRect.Right;
    tv[1].y := fillRect.Bottom;

    // -------------------------------------------------------------------------
    // -> $0000 or BYTE(startColor shr 8) shl 8;
    // ein wenig trciki, GradientFill erwartet als farbwert ein word
    // wobei das farbbyte an erster stelle stehen muss.
    // ich verzichte hierbei gleich auf GetRValue() usw. von Windows. ;-)

    tv[0].Red := $0000 or BYTE(startColor) shl 8;
    tv[0].Green := $0000 or BYTE(startColor shr 8) shl 8;
    tv[0].Blue := $0000 or BYTE(startColor shr 16) shl 8;
    tv[0].Alpha := $0000 or BYTE(startColor shr 24) shl 8;

    tv[1].Red := $0000 or BYTE(endColor) shl 8;
    tv[1].Green := $0000 or BYTE(endColor shr 8) shl 8;
    tv[1].Blue := $0000 or BYTE(endColor shr 16) shl 8;
    tv[1].Alpha := $0000 or BYTE(endColor shr 24) shl 8;

    Result := _GradientFill(DC, @tv, 2, @gr, 1, FillMode) <> 0;
  end else
    Result := FALSE;

  // -------------------------------------------------------------------------
  // sollte global aufgerufen werden zB. in FormDestroy
  if hLib <> 0 then FreeLibrary(hLib);
  // -------------------------------------------------------------------------
end;
Aufruf zB.:

Delphi-Quellcode:
begin
  //...
 
  r := FormX.Clientrect;

  if @wGradientFill <> nil
    then wGradientFill(FormX.Canvas.Handle, r, clRed, clGreen, GRADIENT_FILL_RECT_H)
    else FormX.Canvas.FillRect(r);

Ich wusste doch das wir das in DP schon mal als Thema hatten.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

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

Re: Windows.GradientFill

  Alt 15. Sep 2009, 20:00
Hier mal noch ein Beispiel mit drei Farben:

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}

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

type
  TFillMode = (fmHorizontal = GRADIENT_FILL_RECT_H, fmVertiktal = GRADIENT_FILL_RECT_V);

function wGradientFill(DC: HDC; fillRect: TRect; Col: array of COLORREF; FillMode: TFillMode): Bool;
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;
begin
  if length(col) = 3 then
  begin
    // fillmode direction
    gr[0].UpperLeft := 0;
    gr[0].LowerRight := 1;
    gr[1].UpperLeft := 2;
    gr[1].LowerRight := 3;

    // eckpunkte festlegen
    tv[0].x := fillRect.Left;
    tv[0].y := fillRect.Top;
    tv[1].x := fillRect.Right;
    tv[1].y := fillRect.Bottom div 2;

    tv[2].x := fillRect.Left;
    tv[2].y := fillRect.Bottom div 2;
    tv[3].x := fillRect.Right;
    tv[3].y := fillRect.Bottom;

    // -------------------------------------------------------------------------
    // -> $0000 or BYTE(startColor shr 8) shl 8;
    // ein wenig trckiki, GradientFill erwartet als farbwert ein word
    // wobei das farbbyte an erster stelle stehen muss.
    // ich verzichte hierbei gleich mal auf GetRValue() usw. von Windows. ;-)

    tv[0].Red := BYTE(col[0]) shl 8;
    tv[0].Green := BYTE(col[0] shr 8) shl 8;
    tv[0].Blue := BYTE(col[0] shr 16) shl 8;
    tv[0].Alpha := BYTE(col[0] shr 24) shl 8;

    tv[1].Red := BYTE(col[1]) shl 8;
    tv[1].Green := BYTE(col[1] shr 8) shl 8;
    tv[1].Blue := BYTE(col[1] shr 16) shl 8;
    tv[1].Alpha := BYTE(col[1] shr 24) shl 8;

    tv[2].Red := BYTE(col[1]) shl 8;
    tv[2].Green := BYTE(col[1] shr 8) shl 8;
    tv[2].Blue := BYTE(col[1] shr 16) shl 8;
    tv[2].Alpha := BYTE(col[1] shr 24) shl 8;

    tv[3].Red := BYTE(col[2]) shl 8;
    tv[3].Green := BYTE(col[2] shr 8) shl 8;
    tv[3].Blue := BYTE(col[2] shr 16) shl 8;
    tv[3].Alpha := BYTE(col[2] shr 24) shl 8;

    Result := GradientFill(DC, @tv, length(tv), @gr, length(gr), DWORD(FillMode));
  end else
  begin
    Application.MessageBox('Anzahl der Farben stimmt nicht.', 'wGradientFill:', MB_OK);
    Result := False;
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  wGradientFill(Canvas.Handle, ClientRect, [clNavy, clLime, clYellow], fmVertiktal);
end;

end.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:39 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