Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Bitmapgröße an Textgröße anpassen? (https://www.delphipraxis.net/74568-bitmapgroesse-textgroesse-anpassen.html)

Karstadt 5. Aug 2006 11:28


Bitmapgröße an Textgröße anpassen?
 
hallo. so gehe ich vor:
Delphi-Quellcode:
  with Bild do
  begin
    Bild := TBitmap.create;

    Height := 50; //
    Width := 50; //

    transparentcolor := clWhite;
    transparent := true;

    canvas.TextOut(0,0,edt_text.Text);
  end;
wie kann ich die Heigth und die Width an die Text grösse anpassen? so, das das bild nicht größer ist, als der text selber..

Neutral General 5. Aug 2006 11:36

Re: Bitmapgröße an Textgröße anpassen?
 
Canvas.TextHeight, Canvas.TextWidth ist das was du suchst ;)


Z.B

Delphi-Quellcode:
with Bild do
  begin
    Bild := TBitmap.create;

    Canvas.Font := edt_text.Font;
    Height := Canvas.TextHeight('Dein Text');
    Width := Canvas.TextHeight('Dein Text');

    transparentcolor := clWhite;
    transparent := true;

    canvas.TextOut(0,0,edt_text.Text);
  end;
Gruß
Neutral General

Karstadt 5. Aug 2006 11:44

Re: Bitmapgröße an Textgröße anpassen?
 
:-D :-D :-D

Neutral General 5. Aug 2006 11:46

Re: Bitmapgröße an Textgröße anpassen?
 
Soll das heißen: "Thx es hat geklappt!" ? :mrgreen:

Hawkeye219 5. Aug 2006 11:50

Re: Bitmapgröße an Textgröße anpassen?
 
Noch eine Anmerkung: du solltest den Aufruf des Konstrukturs vor der WITH-Anweisung durchführen. Auch wenn es mit einfachen Variablen offenbar funktioniert, spätestens beim Einsatz strukturierter Variablen wirst du mit ziemlicher Sicherheit eine AV provozieren:

Delphi-Quellcode:
with Bild[Index] do
  begin
    Bild[Index] := TBitmap.Create;
    Width := 50; // <<--- hier wird eine AV auftreten!
Gruß Hawkeye

Karstadt 5. Aug 2006 11:51

Re: Bitmapgröße an Textgröße anpassen?
 
Ja.. super..

...nun ist die Frage, wie mache ich das. wenn dieser text in MEMO eingegeben wird und es wird mit entertaste gearbeitet...

Neutral General 5. Aug 2006 11:56

Re: Bitmapgröße an Textgröße anpassen?
 
du machst für jede zeile ein Bitmap.
Am besten so etwa:

Delphi-Quellcode:
var Bmps: Array of TBitmap;

procedure Ka;
begin
  SetLength(Bmps,Memo1.Lines.Count);
  for i:= 0 to Memo1.Lines.Count-1 do begin
   Bmps[i] := TBitmap.Create;
   with Bmps[i] do begin
    Canvas.Font := Memo1.Font;
    Height := Canvas.TextHeight(Memo1.Lines[i]);
    Width := Canvas.TextHeight(Memo1.Lines[i]);

    transparentcolor := clWhite;
    transparent := true;

   // canvas.TextOut(0,0,edt_text.Text); ka irgenwo halt wieder malen
   end;
  end;
end;
Gruß
Neutral General

Karstadt 5. Aug 2006 11:56

Re: Bitmapgröße an Textgröße anpassen?
 
Delphi-Quellcode:
  Bild := TBitmap.create;

  with Bild do
  begin
    Canvas.Font := edt_text.Font;
    Height := Canvas.TextHeight(edt_text.Text)*edt_text.Lines.Count;
    Width := Canvas.TextWidth(edt_text.Text);
    transparentcolor := clWhite;
    transparent := true;
    for i:= 0 to edt_text.Lines.Count-1 do
    begin
     canvas.TextOut(0,Canvas.TextHeight(edt_text.Text)*i,edt_text.Lines.Strings[i]);
    end;
  end;
die BREITE des bildes wird doch gewaltig sein wenn es 100 zeilensind.. oder?

Karstadt 5. Aug 2006 11:57

Re: Bitmapgröße an Textgröße anpassen?
 
mein fall ist auch richig oder?

am ende soll das ein einziges bild sein ;)

Neutral General 5. Aug 2006 12:00

Re: Bitmapgröße an Textgröße anpassen?
 
Ja ka probiers doch aus.. Lass es laufen und guck ob das passiert was passieren soll ;)
Moment ich programmiere das auch mal..


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:39 Uhr.
Seite 1 von 3  1 23      

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