Autor Beitrag
Coja
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Do 28.11.13 21:25 
Hallo,

ich würde gerne das Aufnahmedatum von mehreren Bilddateien ändern, in dem ich einen Zeitoffset darauf addiere.
Dazu lese ich das Datum ein und versuche es auch zu setzen.:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
//...
//public TimeSpan timediff;
//...
//string path 8 = "C:\Pfad\Zu\Den\Dateien\Bild.jpg";
//...        
System.IO.File.SetCreationTime(path8,System.IO.File.GetCreationTime(path8) + timediff);
                System.IO.File.SetLastWriteTime(path8,System.IO.File.GetLastWriteTime(path8) + timediff);
                System.IO.File.SetLastAccessTime(path8,System.IO.File.GetLastAccessTime(path8) + timediff);


Das Aufnahmedatum kann ich leider weder lesen noch schreiben (siehe Anhang).

Kennt jemand eine Methode dafür?

Viele Grüße Coja

Moderiert von user profile iconChristian S.: Quote- durch C#-Tags ersetzt
Einloggen, um Attachments anzusehen!
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Do 28.11.13 21:48 
Stichwort ist wohl Exif.
Ein fertige Bibliothek wäre zum Beispiel ExifLib.
Coja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Sa 30.11.13 01:28 
user profile iconRalf Jansen hat folgendes geschrieben Zum zitierten Posting springen:
Stichwort ist wohl Exif.
Ein fertige Bibliothek wäre zum Beispiel [url=www.codeproject.com/...T-2-0]ExifLib[/url].


Hallo,
danke, das Datum kann ich jetzt schon einmal auslesen:)
Nun würde ich noch gerne das Datum ändern und das Bild mit dem neuen Datum speichern.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
Image Bild2 = Image.FromFile(pathBild2);

PropertyItem propItem = Bild2.GetPropertyItem(306); // 306 ->Datum

//... hier muss noch eine Konvertierung vom Datums-String zu Byte rein (Ascii)
// StringFormat: 2013:11:01 00:39:16  muss in  propItem.Value gesetzt werden
Bild2.SetPropertyItem(propItem);


Wie im Kommentar zu lesen ist, macht mir die Konvertierung des Datum-Strings (ich habe diese Datum zusätzlich auch als DateTime vorliegen) in die Bytes für propItem.Value zu schaffen.
Kann mir da jemand auf die Sprünge helfen?

Viele Grüße
Coja
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 30.11.13 10:49 
Hallo Coja,

das sollte mittels
ausblenden C#-Quelltext
1:
propItem.Value = dateTime.ToString("<format>");					

doch einfach möglich sein. Den Format-String kannst du dir über Benutzerdefinierte Formatzeichenfolgen für Datum und Uhrzeit entsprechend zusammensetzen.
Coja Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: So 01.12.13 18:00 
Hallo,

für die Konvertierung in einen String habe ich mir schon eine Funktion geschrieben, der String hat das gleiche Format wie das ausgelesene Datum (zum Beispiel 2013:11:01 00:39:16). Hier der COde wie ich das Datum auslese:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
Image Bild2 = Image.FromFile(pathBild2);
    ASCIIEncoding encBild2 = new System.Text.ASCIIEncoding();
    PropertyItem propItem = Bild2.GetPropertyItem(306); // 306->Datum
    String decodedString = encBild2.GetString(propItem.Value); 
    textBox1.Text = "Zeitstempel: " + decodedString;


Nun möchte ich das Datum wieder in die Datei Bild 2 schreiben. Dazu muss der String "2013:11:01 00:39:16" über die Ascii-Codierung in Bytes umgewandelt werden und dann mit
  propItem.Value = gesetzt werden. Bei der Umwandlung des Strings in Byte hakt es derzeit ;)

Viele Grüße
Coja
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 01.12.13 18:49 
Hallo,

also von string nach byte[]? Dann schau dir mal die anderen Methoden von ASCIIEncoding an.