Hi,
[I'm writing this assuming you are using C++ .NET]
this is what I wrote yesterday nite, after I found out you can't create
and assign PropertyItem to an image. I don't know why this behaviour is
by design - makes no sense to me, to go the "save and reload then
modify"-way? Maybe Bob can explain this... ?!?
You have to write a wrapper in C# to retrieve the codec - also a
behaviour by design - and also makes no sense to me, I believe MS
screwed up on this one!
It should be easy to port that code to any other .NET lang...
If you have a problem, drop me a line.
Regards,
Martin
[C#-Wrapper for codec retrievement]
public static ImageCodecInfo GetEncoderCodec(string mimetype)
{
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici=null;
foreach(ImageCodecInfo codec in codecs)
{
if(codec.MimeType==mimetype)
{
ici=codec;
break;
}
}
return ici;
}
[Fill and Write the comment field:]
ImageCodecInfo *ici = ImageCodecHelper::GetEncoderCodec("image/jpeg");
EncoderParameters *ep = new EncoderParameters();
// set quality to 70%
ep->Param[0]=new System:

rawing::Imaging::EncoderParameter(System:

rawing::Imaging::Encoder::Quality, (__int64)70);
//this is the way to get the property Items
static_cast<Bitmap*>(pBLeft->Image)->Save((Application::StartupPath->Concat(S"\\temp.jpg")), ici, ep);
Bitmap *bmp = new Bitmap(Application::StartupPath->Concat(S"\\temp.jpg"));
System:

rawing::Imaging:

ropertyItem *pi[] = bmp->PropertyItems;//static_cast<Bitmap*>(pBLeft->Image)->PropertyItems;
//retrieve comment from given Commentfield
String *str = m_pbHLeft->GetComment();
//convert to unsigned char array and set
//required fields for unrestricted user comment
unsigned char uc_str __gc[]= new unsigned char __gc [str->Length+8];
//undefined charset
for(int i=0; i<8; i++)
{
uc_str = 0;
}
//string data
for(int i=0; i<str->Length; i++)
{
uc_str[i+8] = Convert::ToByte(str->Chars);
}
//exif user comment w/o restriction
pi[0]->Id = 0x9286;
pi[0]->Type = 2;
pi[0]->Len = str->Length+8;
pi[0]->Value = uc_str;
//Set the Property item to the selected Image
static_cast<Bitmap*>(pBLeft->Image)->SetPropertyItem(pi[0]);
//save the image with the properties set