Thema: Delphi Colorpanel berechnen

Einzelnen Beitrag anzeigen

Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Colorpanel berechnen

  Alt 13. Nov 2004, 14:31
Ist ganz einfach das ganze. Dax hasts schon richtig erklärt wies geht:
Delphi-Quellcode:
function GetBlendColor(Basecolor: TColor; Blendcolor: TColor; BlendIntensity: Byte=127): TColor;
function GetValueButMax(AValue: Real; Max: Byte): Byte;
begin
  if AValue > max then result := max else result := trunc(AValue);
end;
type
  TMyColor = record
    red: Byte;
    green: Byte;
    blue: Byte;
  end;
var LF1, LF2: TMyColor;
begin
  LF1.red := GetRValue(Basecolor);
  LF1.green := GetGValue(Basecolor);
  LF1.blue := GetBValue(Basecolor);
  LF2.red := (LF1.red * (255-BlendIntensity) + GetRValue(Blendcolor) * BlendIntensity) div 255;
  LF2.green := (LF1.green * (255-BlendIntensity) + GetGValue(Blendcolor) * BlendIntensity) div 255;
  LF2.blue := (LF1.blue * (255-BlendIntensity) + GetBValue(Blendcolor) * BlendIntensity) div 255; result := rgb(LF2.red, LF2.green, LF2.blue);
end;

procedure FillWithColor(ABitmap: TBitmap; ABaseColor: TColor; ADestColor1: TColor = clWhite; ADestColor2: TColor = clBlack);
var LCountX, LCountY: Integer;
    LFactorX, LFactorY: Extended;
    LTmpColor1, LTmpColor2: TColor;
begin
  LFactorX := 255 / ABitmap.Width;
  LFactorY := 255 / ABitmap.Height;
  for LCountX := 0 to ABitmap.Width - 1 do
  begin
    LTmpColor1 := GetBlendColor(ADestColor1, ABaseColor, Trunc(LCountX * LFactorX));
    for LCountY := 0 to ABitmap.Height do
    begin
      LTmpColor2 := GetBlendColor(LTmpColor1, ADestColor2, Trunc(LCountY * LFactorY));
      ABitmap.Canvas.Pixels[LCountX, LCountY] := LTmpColor2;
    end;
  end;
end;
damit das ganze wie in deinem beispiel aussieht das ganze so aufrufen:

Delphi-Quellcode:
  Image1.Picture.Bitmap.Width := Image1.Width;
  Image1.Picture.Bitmap.Height := Image1.Height;
  FillWithColor(Image1.Picture.Bitmap, RGB(0, 128, 255));
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat