Autor Beitrag
icedre
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: So 13.06.04 17:05 
Hallo,

also...

ich möchte ein Proggi, mit einer Bitmap auf die man dann was schreiben kann, sowas wie ein Bannergenerator...

Also es soll immer die selbe Bitmap sein und der Text denn man drauf schreiben kann mus man verändern können:
- Größe
- Farbe
- Schriftart

Ich hab mich jetzt mal ein bißchen umgeschaut und bin immer wieder auf canvas und textout gestoßen.
Hab´s aber nie hin bekommen.

Ich hoffe mir kann hier jemand helfen...

vielen Dank im voraus, icedre

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 13.06.04 17:28 
Sollte eigentlich kein Problem sein:
ausblenden Delphi-Quelltext
1:
2:
3:
 Image1.Canvas.Font.Color:=clRed;
 Image1.Canvas.Font.Size:=20;
 Image1.Canvas.TextOut(0,0,'Hello World');

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: So 13.06.04 17:30 
Hallo!

Also ich würde das in etwa so machen. Ich schreib das jetzt aus dem Kopf, einige Elemente wirst du also evt. noch abändern müssen.
In einer Paintbox wird der Hintergrund erstellt.

Und los gehts :)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
procedure Bannergenerieren;
var bmp : TBitmap;
begin
  bmp := TBitmap.create;
   try
    bmp.loadfromfile('c:\dasbild.bmp');
   except
     exit;
   end;
  try
    Paintbox1.canvas.draw(0,0,bmp);
    Paintbox1.canvas.font.color := clred;
    Paintbox1.canvas.font.size := 20;    
    Paintbox1.canvas.TextOut(20,20, 'Der Text');    //Parameter 1,2 = x,y Koordinate
  finally
    bmp.free; 
  end;
 end;
end;

{Um Das Bild zu speichern benutzen wir Popov's Code aus den Faq's zum erstellen eines Screenshots}
{Dieser Code ist von Popov geschrieben worden}
function FormularSaveScreenShot(FileName: String; h : hWnd): Boolean;   
var   
  Rec: TRect;   
  iWidth, iHeight: Integer;   
begin   
  with TBitmap.Create do try   
    GetWindowRect(h, Rec);   

    iWidth  := Rec.Right - Rec.Left;   
    iHeight := Rec.Bottom - Rec.Top;   

    Width := iWidth;   
    Height := iHeight;   

    BitBlt(Canvas.Handle, 0, 0, iWidth, iHeight, GetWindowDC(h), 0, 0, SRCCOPY);   

    Result := True;   

    try SaveToFile(Filename) except Result := False end;   
  finally   
    ReleaseDC(h, GetWindowDC(h));   
    Free;   
  end;   
end;

procedure Bildspeichern;
begin
  FormularSaveScreenShot('c:\derbanner', Paintbox1.Handle);
end;


Das müsste es soweit gewesen sein.

edit: Verdammt, Max war schneller :)
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: So 13.06.04 17:55 
Hallo,

und erst mal danke...

Also ist das alles was ich an Code rein "kopieren" soll ?

Wo finde ich die Paintbox, bei welcher Komponente ?

danke ! :D

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: So 13.06.04 18:07 
Die Paintbox ist in der Registerkarte "System".
Und du sollst eigentlich nichts reinkopieren, sondern es verstehen und es dann neu (und besser) schreiben ;)
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: So 13.06.04 18:09 
Karlson hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
{Um Das Bild zu speichern benutzen wir Popov's Code aus den Faq's zum erstellen eines Screenshots}					


Würde ich nicht machen. Was ist, wenn sich ein anderes Fenster teilweise vor der PaintBox befindet? Bei mir wird dann dessen Ecke mitgespeichert...
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: So 13.06.04 18:20 
Ja stimmt.
Aber: Mauszeiger verstecken, fenster bringtofront für 1 Sec, und fertig :)
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 13.06.04 21:22 
Hi,

Karlson hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
{Um Das Bild zu speichern benutzen wir Popov's Code aus den Faq's zum erstellen eines Screenshots}					


ich denke das ganze einfach in ein TBitmap zu kopieren und dieses dann zu speichern sollte der schnellere und sicherere weg sein ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap: TBitmap;
begin
  Bitmap:=TBitmap.Create;
  Bitmap.Width:=PaintBox1.Width;
  Bitmap.Height:=PaintBox1.Height;
  Bitmap.Canvas.CopyRect(Rect(0,0,Bitmap.Width,Bitmap.Height),PaintBox1.Canvas,Rect(0,0,PaintBox1.Width,PaintBox1.Height));
  Bitmap.SaveToFile(FileName);
  Bitmap.Free;
end;


Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: So 13.06.04 21:40 
oh, ich wusste gar nicht das dass auch geht. Aber okay, dann ist das sicher der bessere Weg.
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 15:07 
Hallo,

also hat alles wunderbar geklappt und hab es auch einigermaßen verstanden :lol:

Folgende Probleme noch:

wie kann ich bei :
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);   
var   
  Bitmap: TBitmap;   
begin   
  Bitmap:=TBitmap.Create;   
  Bitmap.Width:=PaintBox1.Width;   
  Bitmap.Height:=PaintBox1.Height;   
  Bitmap.Canvas.CopyRect(Rect(0,0,Bitmap.Width,Bitmap.Height),PaintBox1.Canvas,Rect(0,0,PaintBox1.Width,PaintBox1.Height));   
  Bitmap.SaveToFile(FileName);   
  Bitmap.Free;   
end;

Noch einen "SaveDialog1" einbauen, hab das versucht unter (FileName) mit rein zu bringen, ging aber nicht :(

wie kann ich bei :
ausblenden Quelltext
1:
2:
3:
4:
Paintbox1.canvas.draw(0,0,bmp);   
    Paintbox1.canvas.font.color := clred;   
    Paintbox1.canvas.font.size := 20;       
    Paintbox1.canvas.TextOut(20,20, (Edit1.Text));

(Edit1.Text) einen FontDialog einbauen, damit ich die Schriftart und Größe verändern kann, und bei
ausblenden Quelltext
1:
Paintbox1.canvas.font.color := clred;					

einen ColorDialog einbauen kann, damit ich die Farbe verändern kann.

Da ich noch nie mit den Dialogen gearbeitet habe sondern nur aus diversen Bsp´s kenne, kenne ich mich auch nicht so gut damit aus...


Hoffe das ist nicht zuviel auf einmal :lol:


vielen Dank im voraus, icedre

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Di 15.06.04 15:27 
Diealoge besitzen eine Fuktion namens execute. Diese ist vom typ Boolean und gibt false zurück, wenn der User auf Abbrechen geklickt hat. Also

ausblenden Delphi-Quelltext
1:
if Dialog.Execute then ...					


Dann kann man auf ein paar Eigenschaften zugreifen.

FileName beim SaveDialog ist schon richtig, da ist der eingegebene Dateiname drin. Und beim ColorDialog ist es die Eigenschaft Color, die du brauchst.
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 15:42 
Hallo,

also ich hab das jetzt folgendermaßen gemacht:

Bevor ich den Text, der auf die Bitmap soll, eingebe, drücke ich zuerst den Button "Farbe wählen", der folgendes beinhaltet:
ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.Button3Click(Sender: TObject);
begin
if ColorDialog1.Execute then Paintbox1.canvas.font.color := ColorDialog1.Color;
end;


Aber die Farbe wird trotzdem nicht geändert :?:


Hat sich schon erledigt :D

Hab´s hin bekommen mit dem Color

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 16:00 
Zum Abspeichern:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
  Bitmap:=TBitmap.Create;
  Bitmap.Width:=PaintBox1.Width;
  Bitmap.Height:=PaintBox1.Height;
  Bitmap.Canvas.CopyRect(Rect(0,0,Bitmap.Width,Bitmap.Height),PaintBox1.Canvas,Rect(0,0,PaintBox1.Width,PaintBox1.Height));
  Bitmap.SaveToFile(SaveDialog1.FileName);
  Bitmap.Free;


und dann den SaveDialog:

ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.Button4Click(Sender: TObject);
begin
if SaveDialog1.Execute then Bitmap.SaveToFile := SaveDialog1.FileName ;
end;


Klappt aber dennoch nicht...WARUM ? Ist doch das selbe wie bei ColorDialog oder ?

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Di 15.06.04 16:05 
Ne, so geht das nicht...

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button4Click(Sender: TObject);  
var
  Bitmap: TBitmap;
begin  
  if SaveDialog1.Execute then
  begin
    Bitmap := TBitmap.Create;
    try
      ... //Hier Text zeichnen
    finally
      Bitmap.Free;
    end;
  end;
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 16:07 
So, also das mit dem Abspeichern hab anders gelöst :D

Jetzt hab ich noch Probleme den "FontDialog" mit der "Paintbox1.canvas.font" zu verbinden...
Ich will ja Schriftart und Größe verändern,

hoffe mir kann jemand dabei helfen ...


vielen Dank, icedre

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Di 15.06.04 16:12 
Jetzt scheint es mir langsam, als würdest du nach jemanden Suchen, der dir deine Arbeit abnimmt. Daher bekommst du nur noch folgende Antwort von mir:

TFontDialog + F1; TCanvas + F1, TFont + F1
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 16:22 
Warum die Arbeit abnehmen, die anderen Fragen hab ich mir doch wohl selbst beantwortet und bin auch sehr stolz auf mich selbst (Selbstlob stnkt) :P

Aber trotzdem Danke

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Di 15.06.04 16:25 
Eigenartig, das du immer kurz vorher eine Antwort bekommen hast, wie es geht...
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 16:47 
Tja was soll man machen.... :lol:

Aber jetzt zurück zum Thema.

Wenn ich eine Bitmap laden möchte die ich schon im Formular drin habe durch "Image1",
funktioniert das ganze nicht.
Fehlermeldung:
TImage und TGraphic sind unzulässig.
Ich schätze mal, dass ich eine "Bitmap1" in das Formular rein machen muss, nur finde ich leider keine
Kartei bei Delphi bei der ich Bitmap anstatt Image holen kann, wie stell ich das an, dass nur das eine
Bitmap beschriftet wird, das sich schon im Formular befindet ?

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen
icedre Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Windows XP Prof. , SuSE Linux 9.0 Prof.
Borland Delphi 6.0 Enterprise
BeitragVerfasst: Di 15.06.04 17:08 
So also das Problem mit der Bitmap hab ich auch gelöst, sebstständig

Ich hab jetzt nur das Problem, dass ich die Schriftart und die Größe nicht ändern kann...

_________________
Sprach Abraham zu Braham:
Kann ich deine Frau besamen