Dégradé Lissé

sokoban Messages postés 32 Date d'inscription mardi 4 novembre 2003 Statut Membre Dernière intervention 4 novembre 2006 - 12 sept. 2005 à 23:00
sokoban Messages postés 32 Date d'inscription mardi 4 novembre 2003 Statut Membre Dernière intervention 4 novembre 2006 - 13 sept. 2005 à 22:19
Bonjour,

Je voudrais savoir comment je peux faire un dégradé vraiment lisse (smooth gradient) dans un TImage. J'ai réussi à faire un petit bout de code qui fait passer du jaune au bleu en passant par autant de variantes qu'il y a de lignes dans mon TImage. Pourtant, le résultat n'est pas parfait. Globalement, ça dégrade bien, mais y'a comme un effet de lignes par dessus mon truc...

Voici ma fonction, si qqn connait un algorithme un peu plus performant, ça me brache bien !

procedure TFRMMain.CalculerGradient;
var
  i, nColor1, nColor2, nColor3: integer;
  r1, g1, b1, r2, g2, b2, r3, g3, b3: integer;
begin
  Image1.Picture.Bitmap.Width :=  Image1.Width;
  Image1.Picture.Bitmap.Height := Image1.Height;

  nColor1 := clYellow;

  r1 := GetRValue(nColor1);
  g1 := GetGValue(nColor1);
  b1 := GetBValue(nColor1);

  nColor2 := clBlue;

  r2 := GetRValue(nColor2);
  g2 := GetGValue(nColor2);
  b2 := GetBValue(nColor2);

   for  i : = 0 to Image1.Height do
  begin
    r3 := Trunc(((Image1.Height - i) * r1)/Image1.Height + (i * r2)/Image1.Height);
    g3 := Trunc(((Image1.Height - i) * g1)/Image1.Height + (i * g2)/Image1.Height);
    b3 := Trunc(((Image1.Height - i) * b1)/Image1.Height + (i * b2)/Image1.Height);

    nColor3 := RGB(r3, g3, b3);
    Image1.Canvas.Pen.Color := nColor3;
    Image1.Canvas.MoveTo(0, i);
    Image1.Canvas.LineTo(Image1.Width, i);
  end;
end;



Ghislain "Sokoban" Martin
http://perso.wanadoo.fr/sokoban

2 réponses

sokoban Messages postés 32 Date d'inscription mardi 4 novembre 2003 Statut Membre Dernière intervention 4 novembre 2006
12 sept. 2005 à 23:02
procedure TFRMMain.CalculerGradient;
var
i, nColor1, nColor2, nColor3: integer;
r1, g1, b1, r2, g2, b2, r3, g3, b3: integer;
begin
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := Image1.Height;


nColor1 := clYellow;


r1 := GetRValue(nColor1);
g1 := GetGValue(nColor1);
b1 := GetBValue(nColor1);


nColor2 := clBlue;


r2 := GetRValue(nColor2);
g2 := GetGValue(nColor2);
b2 := GetBValue(nColor2);


for i := 0 to Image1.Height do
begin
r3 := Trunc(((Image1.Height - i) * r1)/Image1.Height + (i * r2)/Image1.Height);
g3 := Trunc(((Image1.Height - i) * g1)/Image1.Height + (i * g2)/Image1.Height);
b3 := Trunc(((Image1.Height - i) * b1)/Image1.Height + (i * b2)/Image1.Height);


nColor3 := RGB(r3, g3, b3);
Image1.Canvas.Pen.Color := nColor3;
Image1.Canvas.MoveTo(0, i);
Image1.Canvas.LineTo(Image1.Width, i);
end;
end;


Ghislain "Sokoban" Martin
http://perso.wanadoo.fr/sokoban
0
sokoban Messages postés 32 Date d'inscription mardi 4 novembre 2003 Statut Membre Dernière intervention 4 novembre 2006
13 sept. 2005 à 22:19
En gros, ce que je cherche à obtenir, ce sont des dégradés aussi beaux que ceux de PhotoShop et autres OpenGL !
Mais apparemment, les fonctions GetRValue, GetGValue, GetBValue et RGB associées à une simple fonction linéaire ne suffisent pas...


Ghislain "Sokoban" Martin
http://perso.wanadoo.fr/sokoban
0
Rejoignez-nous