Add EXIF Tag to JPEG

B

BluDog

Hi

I was wandering if anyone knew if it was possible to add custom EXIF
tags (such as Photographer and Title) to a JPEG image, or to modify
the existing tags (such as ImageDescription).

There is an extremely good article on Code Project for reading these
tags, but I cannot find any information on how to modify them:

http://www.codeproject.com/cs/media/photoproperties.asp

Thanks

Blu.
 
M

mphanke

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::Drawing::Imaging::EncoderParameter(System::Drawing::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::Drawing::Imaging::propertyItem *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
 
B

BluDog

forgot about this, you might want to download this file and have a look
at it. There you will find all the valid tag IDs for the Exif2.2 tags.

http://www.exif.org/Exif2-2.PDF

Thanks mate. Looks great, unfortunately I only have knowledge of VB,
could you give me a hand on the conversion side please?

Cheers

Blu
 
M

mphanke

I don't know much about VB. But you only have to find the appropriate
calls to the namespace funcs and then replace them... But I will give my
best to support you on this - give it a try and then post the code and
tell me where the problem is... I should be able to help you.

Martin
 
E

Eric Hourant

Blu,
You can also use an ocx from WaterMarker.
Check on www.watermarker.com and follow the AIS Exif ActiveX. I use it for
reading exif information but it can also be used to write infos.

HTH

Eric
 
B

BluDog

Martin

I have converted the C# wrapper bit to VB no probs:

Public Shared Function GetEncoderCodec(ByVal mimetype As String) As
ImageCodecInfo

Dim codecs() As ImageCodecInfo =
ImageCodecInfo.GetImageEncoders()
Dim codec As ImageCodecInfo

For Each codec In codecs
If codec.MimeType = mimetype Then Return codec
Next

End Function


But the rest, this is C++, i am assuming from your post that this can
only be acheived using C++ and cannot be converted to VB?

Is this correct?

Cheers

Blu
 
M

mphanke

Hi,

no this is all .Net standard stuff. You don't have to worry about quit a
lot of things like the pointer stuff. This is normal object as it is in
VB. Give it a try, you should encounter no problems.

I'm leaving office now, if you have any further questions on this, I
will answer them tomorrow morning.

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top