Thema: Delphi Graustufen....

Einzelnen Beitrag anzeigen

Benutzerbild von Wormid
Wormid

Registriert seit: 26. Aug 2003
Ort: Steinfurt
292 Beiträge
 
Delphi XE2 Professional
 
#3

Re: Graustufen....

  Alt 2. Dez 2003, 15:09
Hier mal ein paar kleine Routinchen, die dich der Lösung vielleicht näher bringen. Die Prozedur "DrawFrostedGlass" macht im Grunde das was du suchst, glaube ich... Zumindestens liesse sich das daraus ableiten - in "Milk" könnte nämlich der Grauwert drinstehen, der dir so vorschwebt.

Delphi-Quellcode:
// Einen TColor-Wert in die einzelnen RGB-Anteile umrechnen
procedure SplitColorToRGB(const Color: TColor; var r, g, b: Byte);
begin
  r := ColorToRGB(Color) and $0000FF;
  g := (ColorToRGB(Color) and $00FF00) shr 8;
  b := (ColorToRGB(Color) and $FF0000) shr 16;
end;

// Einzelne RGB-Anteile in einen TColor-Wert umrechnen
function RGBToColor(const r, g, b: Byte): TColor;
begin
  Result := TColor(r + (g shl 8) + (b shl 16));
end;

// Alphablending...
function CalcBlending(const Source, Back, Alpha: Byte): Byte;
begin
  Result := Back + ((Source - Back) * Alpha div 255);
end;

// "Milchglasscheibe" mit einem 1-Pixel-Rahmen auf ein Bitmap zeichnen...
procedure DrawFrostedGlass(var Bitmap: TBitmap; GlassRect: TRect; const Milk: TColor = clWhite; Alpha: Byte = 128);
var r, g, b: Byte;
    x, y: Integer;
    P: PByteArray;
begin
  // Den Rahmen malen
  with Bitmap.Canvas, Bitmap.Canvas.Pen do begin
    Color := Milk;
    Style := psSolid;
    Width := 1;
    Brush.Style := bsClear;
    Rectangle(GlassRect);
  end;

  // Vorbereitungen für das AlphaBlending
  Bitmap.PixelFormat := pf24Bit;
  GlassRect.Left := (GlassRect.Left * 3) + 3;
  GlassRect.Right := (GlassRect.Right * 3) - 3;
  SplitColorToRGB(Milk, r, g, b);

  // Zeilen einzeln auslesen und Pixel einzeln verwursten...
  for y := GlassRect.Top + 1 to GlassRect.Bottom - 1 do
  begin
    P := Bitmap.ScanLine[y];
    x := GlassRect.Left;
    repeat
      P[x+0] := CalcBlending(P[x+0], r, Alpha);
      P[x+1] := CalcBlending(P[x+1], g, Alpha);
      P[x+2] := CalcBlending(P[x+2], b, Alpha);
      Inc(x, 3);
    until x >= GlassRect.Right;
  end;
end;
Debuggers don't remove Bugs, they only show them in Slow-Motion.
  Mit Zitat antworten Zitat