Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi canvas textout? (https://www.delphipraxis.net/108681-canvas-textout.html)

snow 17. Feb 2008 19:27


canvas textout?
 
Hallo

wie kann ich einen canvas.textout ausführen lassen, dessen schriftfarbe immer interveniert zum hintergrund ist.

Dabei soll nicht die farbe des gesammten textes gleich sein sondern ähnlich wie bei TGauge.

http://b.imagehost.org/0114/gauge.gif

gruß snow

DeddyH 17. Feb 2008 19:34

Re: canvas textout?
 
In meiner Gauges.pas sieht die Paint-Methode so aus:
Delphi-Quellcode:
procedure TGauge.Paint;
var
  TheImage: TBitmap;
  OverlayImage: TBltBitmap;
  PaintRect: TRect;
begin
  with Canvas do
  begin
    TheImage := TBitmap.Create;
    try
      TheImage.Height := Height;
      TheImage.Width := Width;
      PaintBackground(TheImage);
      PaintRect := ClientRect;
      if FBorderStyle = bsSingle then InflateRect(PaintRect, -1, -1);
      OverlayImage := TBltBitmap.Create;
      try
        OverlayImage.MakeLike(TheImage);
        PaintBackground(OverlayImage);
        case FKind of
          gkText: PaintAsNothing(OverlayImage, PaintRect);
          gkHorizontalBar, gkVerticalBar: PaintAsBar(OverlayImage, PaintRect);
          gkPie: PaintAsPie(OverlayImage, PaintRect);
          gkNeedle: PaintAsNeedle(OverlayImage, PaintRect);
        end;
        TheImage.Canvas.CopyMode := cmSrcInvert;
        TheImage.Canvas.Draw(0, 0, OverlayImage);
        TheImage.Canvas.CopyMode := cmSrcCopy;
        if ShowText then PaintAsText(TheImage, PaintRect);
      finally
        OverlayImage.Free;
      end;
      Canvas.CopyMode := cmSrcCopy;
      Canvas.Draw(0, 0, TheImage);
    finally
      TheImage.Destroy;
    end;
  end;
end;
Besonderes Augenmerk solltest Du mal auf die CopyModes legen.

Und hier noch die PaintAsText-Methode:
Delphi-Quellcode:
procedure TGauge.PaintAsText(AnImage: TBitmap; PaintRect: TRect);
var
  S: string;
  X, Y: Integer;
  OverRect: TBltBitmap;
begin
  OverRect := TBltBitmap.Create;
  try
    OverRect.MakeLike(AnImage);
    PaintBackground(OverRect);
    S := Format('%d%%', [PercentDone]);
    with OverRect.Canvas do
    begin
      Brush.Style := bsClear;
      Font := Self.Font;
      Font.Color := clWhite;
      with PaintRect do
      begin
        X := (Right - Left + 1 - TextWidth(S)) div 2;
        Y := (Bottom - Top + 1 - TextHeight(S)) div 2;
      end;
      TextRect(PaintRect, X, Y, S);
    end;
    AnImage.Canvas.CopyMode := cmSrcInvert;
    AnImage.Canvas.Draw(0, 0, OverRect);
  finally
    OverRect.Free;
  end;
end;
P.S.: Du meintest sicher invertieren und nicht intervenieren ;)

snow 17. Feb 2008 19:41

Re: canvas textout?
 
So wie ich das jetz verstehe malt er den text auf ein bitmap und malt dieses dann auf das Große Bitmap. Dabei setzt er den CopyMode := cmSrcInvert;

Aber mal ne andere Frage: Wie kommst du an diese Infos? liegen die Delphi PE bei?

gruß snow

lbccaleb 17. Feb 2008 19:47

Re: canvas textout?
 
Zitat:

Zitat von snow
Aber mal ne andere Frage: Wie kommst du an diese Infos? liegen die Delphi PE bei?

sagte er ja fast:
Zitat:

Zitat von DeddyH
In meiner Gauges.pas

ja diese sind in delphi dabei, durchsuche einfach mal die ordner ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz