![]() |
Text auf ein Foto speichern
Hallo zusammen,
ich nutze noch Delphi 7, also schon eine etwas betagtere Version. Gibt es dort eine Möglichkeit, einen String als Overlay auf ein Foto zu schreiben und anschließend wieder abzuspeichern? Ich habe ein JPG in ein TImage geladen, dort bekomme ich aber den Text nicht drauf. Text zeichnen kann ich nur in einer Canvas. Wie aber verbinde ich beides? Hintergrund: ich möchte auf Fotos das Aufnahmedatum und Uhrzeit darstellen, wie es früher noch auf analogen kameras oftmals der Fall war. Ich bin leider kein Delphi-Profi, habe das Programm schon ewig (wirklich ewig) nicht mehr benutzt und bin auch beim Programmieren mittlerweile ziemlich raus. Viellicht könnt ihr mir aber ja dennoch helfen. Vielen Dank schon mal! |
AW: Text auf ein Foto speichern
Klappt denn ein
Delphi-Quellcode:
nicht?
Image1.Picture.Bitmap.Canvas.TextOut();
|
AW: Text auf ein Foto speichern
Hallo KodeZwerg,
keine Ahnung warum es gestern nicht funktioniert hat. Ich habe auch
Code:
probiert, ich habe dann jedes Mal beim Speichern ein Bild mit einer Dateigröße von 0 Byte erhalten.
Image1.Picture.Bitmap.Canvas.TextOut();
Seltsamerweise geht es heute... Dann lag ich ja gar nicht so falsch. Vielen Dank für deine schnelle Hilfe und viele Grüße! |
AW: Text auf ein Foto speichern
Gerne, wenn wieder was ist, hier wird geholfen 8-)
|
AW: Text auf ein Foto speichern
Zitat:
In
Delphi-Quellcode:
ist die Bild-Komponente drin, bei .Bitmap, .Icon usw. wird diese Komponente gecastet, vorher gelöscht und eine Neue erstellt (ohne den Bildinhalt zu übernehmen), da der enthaltene TGraphic-Nachfahre nicht dem gewünschten Typ entspricht, also hier dem TBitmap.
Image1.Picture.Graphic
Zitat:
PS: Die Delphi-Komponente kann sowas nicht (PNG-Komponenten von Fremdherstellern eventuell), aber wie wäre es mit einem Multi-Layer-PNG? Eine teiltransparente Grafik mit dem Text über das eigentliche Foto legen, dann hast du deinen Efekt, aber auch der ursprüngliche Bildinhalt bleibt erhalten. Also man könnte somit diesen Text auch wieder entfernen und hätte das Bild ohne "Löcher" zurück. |
AW: Text auf ein Foto speichern
So in etwa habe ich es bei mir
Delphi-Quellcode:
procedure BitmapMake24Bit(const ABitmap: TBitmap);
var LTempBitmap: TBitmap; begin if ABitmap.PixelFormat <> pf24bit then begin LTempBitmap := TBitmap.Create; try LTempBitmap.PixelFormat := pf24bit; LTempBitmap.SetSize(ABitmap.Width, ABitmap.Height); LTempBitmap.Canvas.Draw(0, 0, ABitmap); ABitmap.PixelFormat := pf24bit; ABitmap.Canvas.Draw(0, 0, LTempBitmap); finally FreeAndNil(LTempBitmap); end; end; end;
Delphi-Quellcode:
Image1.Picture.LoadFromFile('EinJpegBild.jpg');
BitmapMake24Bit(Image1.Picture.Bitmap); Image1.Picture.Bitmap.Canvas.Brush.Style := bsClear; Image1.Picture.Bitmap.Canvas.Font.Size := 11; Image1.Picture.Bitmap.Canvas.Font.Color := clRed; Image1.Picture.Bitmap.Canvas.Font.Style := [fsBold]; Image1.Picture.Bitmap.Canvas.TextOut(5, 5, 'Delphi-PRAXiS'); |
AW: Text auf ein Foto speichern
Hallo,
so geht es auch:
Delphi-Quellcode:
procedure TForm2.TextToPicture;
var jp: TJPEGImage; //in der uses Anweidung Vcl.Imaging.Jpeg hinzufügen! //Für D7 muss nur Jpeg hinzugefügt werden begin jp:=TJPEGImage.Create; jp.LoadFromFile('C:\Users\...\Pictures\Bild1.JPG'); Image1.Picture.Bitmap.Assign(jp); Image1.Picture.Bitmap.Canvas.TextOut(10,10,'Hallo'); jp.Assign(Image1.Picture.Bitmap); jp.SaveToFile('C:\Users\..\Pictures\Bild2.JPG'); jp.Free; end; |
AW: Text auf ein Foto speichern
Und ein bisschen hübscher könnte es hiermit gehen:
![]() [edit] @ghubi01: Da fehlt ein Ressourcen-Schutzblock (try...finally) [/edit] |
AW: Text auf ein Foto speichern
Hallo,
@DeddyH: Das ist mir schon klar, dass hier noch ein try … finally Block rein muss. Hab ich mir hier im Beispiel aus Bequemlichkeit gespart. :-D Ich muss aber noch anmerken, dass sich bei meinem Beispiel die dpi-Zahl und die Dateigröße in der gespeicherten Datei ändert. Wie ich das beeinflussen kann, weis ich noch nicht. :? |
AW: Text auf ein Foto speichern
Moin...:P
Zitat:
Community Edition: ![]() PS: Wenn du von D7 umsteigst...erwarte einen Kulturschock! 8-) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:30 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