Hallo Michael,
zum Beispiel bei JPG oder BMP - Dateien wird zwar ein Author oder Titel in
die Properties geschrieben und gelesen, aber das steht dann nicht dort,
wenn man mit dem Explorer auf die Eigenschaften der Datei geht (Vista) ???
Bei Bildern wie JPG sind es die EXIF-Eigenschaften,
die da an die Bild-Informationen anghängt sind.
Achtung, andere Formate (etwa PNG) können das wiederum
nicht. Ansonsten geht das über .NET mit JPG dann prinzipiell mit den:
[Image.PropertyItems-Eigenschaft (System.Drawing)]
http://msdn2.microsoft.com/de-de/library/system.drawing.image.propertyitems(vs.80).aspx
Ansätze leider so auf codeproject etc. oft
nicht unter Vista funktionsfähig. Hier aber eine
Möglichkeit über ImageCodecInfo, z.B.:
enum Props
{
Title = 40091, Comment = 40092, Author = 40093
}
enum EType : short { UnicodeString = 1 }
string fileName=@"Piet.jpg"; string fileName2=@"Piet2.jpg";
string title; string comment; string author;
Image img; const int compression=81;
private void Form1_Load(object sender, EventArgs e)
{
img = Image.FromFile(fileName);
foreach (PropertyItem pi in img.PropertyItems)
{
SetPropertyString(ref title, pi, Props.Title);
SetPropertyString(ref comment, pi, Props.Comment);
SetPropertyString(ref author, pi, Props.Author);
}
SetProperty(Props.Author, "Michael Erlinger");
SaveJPGWithCompressionSetting(img, fileName2, compression);
}
private void SetProperty(Props props, string value)
{
PropertyItem prop = img.GetPropertyItem((int)props);
prop.Value = Encoding.Unicode.GetBytes(value + '\0');
prop.Len = prop.Value.Length;
prop.Type = (short)EType.UnicodeString;
img.SetPropertyItem(prop);
}
private void SetPropertyString(ref string var,
PropertyItem pi, Props props)
{
if (pi.Id == (int)props && pi.Type == (short)EType.UnicodeString)
{
var = Encoding.Unicode.GetString(pi.Value);
var = var.Substring(0, Math.Max(var.Length - 1, 0));
}
}
private static ImageCodecInfo GetEncoderInfo(
string mimeType)
{
int j; ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
} return null;
}
private void SaveJPGWithCompressionSetting(Image image,
string szFileName, long lCompression)
{
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter(System.Drawing.
Imaging.Encoder.Quality, lCompression);
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
image.Save(szFileName, ici, eps);
}
//===========
[EXIF.org - EXIF and related resources]
http://www.exif.org/
[Photo Properties - The Code Project - Multimedia]
http://www.codeproject.com/cs/media/photoproperties.asp
ciao Frank
--
Dipl.Inf. Frank Dzaebel [MCP/MVP C#]
http://Dzaebel.NET