AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi TSmoothLabel verbessern
Thema durchsuchen
Ansicht
Themen-Optionen

TSmoothLabel verbessern

Ein Thema von CReber · begonnen am 30. Jan 2005 · letzter Beitrag vom 31. Jan 2005
Antwort Antwort
Benutzerbild von CReber
CReber

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#1

TSmoothLabel verbessern

  Alt 30. Jan 2005, 20:36
SirThornberry hatte letztens eine Unit bereitgestellt mit der man ein Label weichzeichnen kann. Leider funktioniert dieser nicht mit ScanLines, sodass der Code sehr langsam ist. Nun gibt es ja im Forum genug Codes mit ScanLines die alle mit Bitmaps funktionieren. Weiß jemand wie man die Codes auf Labels anwenden kann? Ich hab leider keine Ahnung von grafischen Sachen und auch wenig Lust mich da einzudenken

http://www.delphipraxis.net/internal...ct.php?t=10043
http://www.delphipraxis.net/internal...ct.php?t=24623
http://www.delphipraxis.net/internal...ct.php?t=14072

Delphi-Quellcode:
unit USmoothLabel;

interface

uses
  Windows, Classes, Controls, Graphics;

type
  TSmoothLabel = class(TGraphicControl)
  private
    fSmoothFactor: Byte;
    function FGetCaption: TCaption;
    procedure FSetCaption(const Value: TCaption);
    procedure FSetSmoothfactor(AValue: Byte);
  public
    constructor Create(AOwner: TComponent); override;
    procedure Paint; override;
  published
    property Caption read FGetCaption write FSetCaption;
    property Font;
    property Smoothfactor: Byte read fSmoothFactor write FSetSmoothfactor default 2;
  end;

procedure Register;

implementation

procedure Antialiasing(const DC: TCanvas; const Rectangle: TRect);
  type TRGBTripleArray = array[0..32768] of TRGBTriple; // MaxWidth of ScanLine
       pRGBTripleArray = ^TRGBTripleArray; // Pointer auf TRGBTripleArray
  var cx, cy : Smallint;
      r, g, b : Byte;
      Row1 : pRGBTripleArray;
      Row2 : pRGBTripleArray;
      Row3 : pRGBTripleArray;
      TEMP : TBitmap;
      CurRect : TRect;
begin
  TEMP := TBitmap.Create;
  try
    with TEMP do begin
      Width := Rectangle.Right - Rectangle.Left;
      Height := Rectangle.Bottom - Rectangle.Top;
      CurRect := Rect(0, 0, Width, Height);
      PixelFormat := pf24Bit;
      Canvas.CopyRect(CurRect, DC, Rectangle);
      with Canvas do begin
        for cy := 1 to (Height - 2) do begin
          Row1 := ScanLine[cy - 1];
          Row2 := ScanLine[cy];
          Row3 := ScanLine[cy + 1];

          for cx := 1 to (Width - 2) do begin
            r := (Row1[cx - 1].rgbtRed+Row1[cx].rgbtRed+
            Row1[cx + 1].rgbtRed+
            Row2[cx - 1].rgbtRed+
            Row2[cx + 1].rgbtRed+
            Row2[cx - 1].rgbtRed+
            Row3[cx].rgbtRed+
            Row3[cx + 1].rgbtRed+
            Row3[cx].rgbtRed) div 9;

            g := (Row1[cx - 1].rgbtGreen+
            Row1[cx].rgbtGreen+
            Row1[cx + 1].rgbtGreen+
            Row2[cx - 1].rgbtGreen+
            Row2[cx + 1].rgbtGreen+
            Row2[cx - 1].rgbtGreen+
            Row3[cx].rgbtGreen+
            Row3[cx + 1].rgbtGreen+
            Row3[cx].rgbtGreen) div 9;

            b := (Row1[cx - 1].rgbtBlue+
            Row1[cx].rgbtBlue+
            Row1[cx + 1].rgbtBlue+
            Row2[cx - 1].rgbtBlue+
            Row2[cx + 1].rgbtBlue+
            Row2[cx - 1].rgbtBlue+
            Row3[cx].rgbtBlue+
            Row3[cx + 1].rgbtBlue+
            Row3[cx].rgbtBlue) div 9;
            Row2[cx].rgbtBlue := b;
            Row2[cx].rgbtGreen := g;
            Row2[cx].rgbtRed := r;
          end;
        end;
      end;
      DC.CopyRect(Rectangle, Canvas, CurRect);
    end;
  finally
    TEMP.Free;
  end;
end;

constructor TSmoothlabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fSmoothFactor := 2;
  SetBounds(Left, Top, 100, 25);
end;

function GetBlendColor(Basecolor: TColor; Blendcolor: TColor; BlendIntensity: Byte=127): TColor;
  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;// + helligkeit) / 2, 255);
  LF2.green := (LF1.green * (255-BlendIntensity) + GetGValue(Blendcolor) * BlendIntensity) div 255;// + helligkeit) / 2, 255);
  LF2.blue := (LF1.blue * (255-BlendIntensity) + GetBValue(Blendcolor) * BlendIntensity) div 255;// + helligkeit) / 2, 255);

  Result := rgb(LF2.red, LF2.green, LF2.blue);
end;

procedure TSmoothlabel.Paint;
  var LTmpPic : TBitmap;
      LCountX, LCountY : Integer;
      LColor, LFontColor : TColor;
begin
  LTmpPic := TBitmap.Create;
  LTmpPic.PixelFormat := pf8bit;
  LTmpPic.Width := Width * fSmoothFactor;
  LTmpPic.Height := Height * fSmoothFactor;
  LTmpPic.Canvas.Font.Assign(Font);
  LTmpPic.Canvas.Font.Color := clBlack;
  LTmpPic.Canvas.Font.Height := LTmpPic.Canvas.Font.Height * fSmoothFactor;
  LTmpPic.Canvas.TextOut(0, 0, Caption);
  Antialiasing(LTmpPic.Canvas, Rect(0, 0, LTmpPic.Width, LTmpPic.Height));
  LTmpPic.Canvas.StretchDraw(Rect(0, 0, Width, Height), LTmpPic);
  LFontColor := Font.Color;
  for LCountY := 0 to Height - 1 do begin
    for LCountX := 0 to Width - 1 do begin
      LColor := GetBlendColor(LFontColor, GetPixel(Canvas.Handle, LCountX, LCountY), GetRValue(GetPixel(LTmpPic.Canvas.Handle, LCountX, LCountY)));
      SetPixel(Canvas.Handle, LCountX, LCountY, LColor);
    end;
  end;
  LTmpPic.Free;
end;

function TSmoothlabel.FGetCaption: TCaption;
begin
  Result := inherited Caption;
end;

procedure TSmoothlabel.FSetCaption(const Value: TCaption);
begin
  if Value <> Caption then
  begin
    inherited Caption := Value;
    Repaint;
  end;
end;

procedure TSmoothlabel.FSetSmoothfactor(AValue: Byte);
begin
  if AValue < 1 then
    AValue := 1
  else if AValue > 5 then
    AValue := 5;
  if AValue <> fSmoothFactor then begin
    fSmoothFactor := AValue;
    Repaint;
  end;
end;

procedure Register;
begin
  RegisterComponents('Zusätzlich', [TSmoothLabel]);
end;


end.
Angehängte Dateien
Dateityp: zip tsmoothlabel_127.zip (5,3 KB, 18x aufgerufen)
Christian Reber
  Mit Zitat antworten Zitat
Benutzerbild von CReber
CReber

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#2

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 17:54
*push it to the moon
Christian Reber
  Mit Zitat antworten Zitat
mytar

Registriert seit: 30. Mai 2004
Ort: Zermatt
411 Beiträge
 
Delphi 6 Enterprise
 
#3

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 18:33
Könntest du ein Bild anhängen wie das mit TLabel und TSmoothedLabel aussieht?

Danke
Francis Obikwelu
greetz
mytar
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#4

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 18:55
Verschnellern könnte es man mit Hier im Forum suchenBitblt
Thomas
  Mit Zitat antworten Zitat
Benutzerbild von CReber
CReber

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#5

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 20:47
Screenshot added..
Miniaturansicht angehängter Grafiken
screeny_211.png  
Christian Reber
  Mit Zitat antworten Zitat
Kernel32.DLL
(Gast)

n/a Beiträge
 
#6

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 21:05
och, sieht ja ganz nett aus...

*download*
  Mit Zitat antworten Zitat
Benutzerbild von CReber
CReber

Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
 
Delphi 2006 Professional
 
#7

Re: TSmoothLabel verbessern

  Alt 31. Jan 2005, 21:21
das soll nur schneller sein
Christian Reber
  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 04:13 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