Autor Beitrag
ebs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 213

Suse Linux 9.2, Win 98, Win NT, Win XP, Win for Workgroups, Win XP SP2, Dos 6.1
D3 Prof, D2005 PE, Delphi 2006 Prof.
BeitragVerfasst: Di 05.07.05 13:16 
Hallo!
Ich habe mal wieder ein Problem, und zwar wollte ich mit Hilfe von Canvas einen Farbverlauf, z.B. von Rot nach Grün zeichnen. Das ist dabei rausgekommen: :evil:

Wie man sieht, ist kein Übergang, sondern am Anfang von Rot nach Schwarz, und so weiter. Ich vermute dass hat damit zu tun, dass ich einfach die Color Integer hochgehe, und irgendwann ein Sprung drin ist.

Also wie könnte ich jetzt solche Farbübergänge zeichnen?

Danke :D
Einloggen, um Attachments anzusehen!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 05.07.05 13:43 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
procedure DrawGradient(const Canvas: TCanvas; Color1, Color2: TColor; Rect: TRect);
var
 Y, R, G, B: Integer;
 RColor1, GColor1, BColor1: Integer;
 RColor2, GColor2, BColor2: Integer;
begin
 Color1:=ColorToRGB(Color1);
 Color2:=ColorToRGB(Color2);

 RColor1:=GetRValue(Color1);
 GColor1:=GetGValue(Color1);
 BColor1:=GetBValue(Color1);

 RColor2:=GetRValue(Color2);
 GColor2:=GetGValue(Color2);
 BColor2:=GetBValue(Color2);

 Canvas.Pen.Width:=1;
 Canvas.Pen.Style:=psInsideFrame;

 for Y:=Rect.Top to Rect.Bottom-1 do
 begin
   R:=Round(RColor1 + ((RColor2 - RColor1) * Y / (Rect.Bottom - Rect.Top)));
   G:=Round(GColor1 + ((GColor2 - GColor1) * Y / (Rect.Bottom - Rect.Top)));
   B:=Round(BColor1 + ((BColor2 - BColor1) * Y / (Rect.Bottom - Rect.Top)));

   Canvas.Brush.Color:=RGB(R, G, B);
   Canvas.FillRect(Classes.Rect(Rect.Left, Y, Rect.Right, Y+1));
 end;
end;

ausblenden Delphi-Quelltext
1:
  DrawGradient(Canvas, clRed, clBlue, ClientRect);					
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 05.07.05 13:50 
Bei Farbübergängen musst du die einzelnen Farbübergänge einzeln bearbeiten, d.h. R G und B getrennt..

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ebs Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 213

Suse Linux 9.2, Win 98, Win NT, Win XP, Win for Workgroups, Win XP SP2, Dos 6.1
D3 Prof, D2005 PE, Delphi 2006 Prof.
BeitragVerfasst: Di 05.07.05 13:53 
Danke, vielen Dank :D :D :D
So funktionierts!!!