Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi GDI+ Variante zu TextRect (https://www.delphipraxis.net/171179-gdi-variante-zu-textrect.html)

Tonic1024 24. Okt 2012 16:14

GDI+ Variante zu TextRect
 
Ich baue grad eine Bildschirmausgabe von Canvas auf GDI+ um. Bei folgender Zeile kommt mein fast abgeschlossener Umbau nun aber ins stocken.

Delphi-Quellcode:
Canvas.Textrect(Textfeld, Text, [tfWordBreak]);
Gibts in dem ganzen Parameter Kuddelmuddel eine einfache Lösung für das Problem oder muss ich anfangen Buchstaben für nen selbstgebauten Zeilenumbruch zu zählen?

Gruß,

Toni

Bummi 24. Okt 2012 16:24

AW: GDI+ Variante zu TextRect
 
ohne Library?
Delphi-Quellcode:
const
  S = 'Ein kleiner Testtest der etwas länger werden könnte';
var
  r:Trect;
begin
  r := Rect(40, 10, 100, 100);
  DrawTextEx(Canvas.Handle, PChar(S), length(S),r,DT_WORDBREAK,nil)
end;

http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Tonic1024 24. Okt 2012 16:32

AW: GDI+ Variante zu TextRect
 
Irgendwie hatte ich schon das Gefühl, dass du dich auf das Thema stürzen wirst. :-D

Ich verwende die Units von progdigy.com. DrawTextEx scheinen aber nicht enthalten zu sein.:?

Bummi 24. Okt 2012 16:42

AW: GDI+ Variante zu TextRect
 
Sorry, ich war wieder mal fasch abgebogen

Delphi-Quellcode:
Procedure BeispielTextout(graphics:TGPGraphics;Const TheText:String;Rect:TGPRectF;Color:TGPColor;HAlign,VAlign:TStringAlignment;Size:Integer=10;FontName:String='Arial');
var
  StringFormat:TGPStringFormat;
  FontFamily : TGPFontFamily;
  Font      : TGPFont;
  Pen  : TGPPen;
  Brush : TGPSolidBrush;
begin
   StringFormat:= TGPStringFormat.Create;
   FontFamily := TGPFontFamily.Create(FontName);
   Font      := TGPFont.Create(FontFamily, Size, FontStyleRegular, UnitPixel);
   Pen  := TGPPen.Create(Color);
   Brush := TGPSolidBrush.Create(Color);
   stringFormat.SetAlignment(HAlign);
   stringFormat.SetLineAlignment(VAlign);
   graphics.DrawString(TheText,-1,Font,Rect,stringformat,Brush);
   Pen.Free;
   Brush.Free;
   StringFormat.Free;
   FontFamily.Free;
   Font.Free;
end;
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Tonic1024 24. Okt 2012 16:55

AW: GDI+ Variante zu TextRect
 
Stringformat... Ich hätt dich mal gleich fragen sollen statt den halben Nachmittag sinnlos umher zu googeln. :wink:

Danke, klappt.

Toni

Bummi 24. Okt 2012 16:56

AW: GDI+ Variante zu TextRect
 
Wenn Du am Umstellen bist wirst Du früher oder später bei einem Problem aufschlagen, welches mich seinerzeit Nerven gekostet hat. TGPImage aus TGraphic's zu bekommen.
Delphi-Quellcode:
//2010 by Thomas Wassermann
// Halten von Grafiken in Stream zur Verwendung als TGPImage
    TGPImageWrapper=Class(TObject)
       private
       FImage: TGPImage;
       FStream: TMemoryStream;
       public
       Constructor Create(FileName: String);overload;
       Constructor Create(AGraphic:TGraphic);overload;
       Destructor Destroy;override;
       Public
       Property Image:TGPImage read FImage;
    end;


constructor TGPImageWrapper.Create(AGraphic: TGraphic);
begin
  inherited Create;
  FStream := TMemoryStream.Create;
  AGraphic.SaveToStream(FStream);
  Fimage:= TGPImage.Create(TStreamAdapter.Create(FStream));
end;

constructor TGPImageWrapper.Create(FileName: String);
begin
  inherited Create;
  Fimage:= TGPImage.Create(FileName);
end;

destructor TGPImageWrapper.Destroy;
begin
  FImage.Free;
  FStream.Free;
  inherited;
end;


// Verwendung on TGPImages aus einer Imagelist (z.B. 32-Bit, PNG's transparent)

procedure CreateGPList(il:TDragImageList;var ol:TObjectList<TGPImageWrapper>);
var
  i:Integer;
  ico:TIcon;
begin
  ol := TObjectList<TGPImageWrapper>.Create;
  ol.OwnsObjects := true;
  for I := 0 to il.Count - 1  do
    begin
      ico:=TIcon.Create;
      try
        IL.GetIcon(i,ico);
        ol.Add(TGPImageWrapper.Create(ico));
      finally
        ico.Free;
      end;
    end;
end

Tonic1024 24. Okt 2012 17:05

AW: GDI+ Variante zu TextRect
 
Ja, das war knifflig. Hab das so gelöst: TStreamAdapter Patch

Aber danke für den Code und das vorausschauende mitdenken - erneut... Könnte sich noch als nützlich erweisen. :-D

Toni


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:43 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