S
Simon Kravis
Guest
I am trying to copy all and modify metadata some EXIF fields from a JPEG file using the code below:
public void CopyAndSetMetadata(string sourceFile, string destFile, string sXPTitle, string sXPSubject,
string sXPComment, int Width, int Height)
{
uint paddingAmount = 4096;
/
using (Stream sourceStream = System.IO.File.Open(sourceFile, FileMode.Open, FileAccess.Read))
{
BitmapDecoder sourceDecoder = BitmapDecoder.Create(sourceStream, createOptions, BitmapCacheOption.None); // Check source is has valid frames
if (sourceDecoder.Frames[0] != null && sourceDecoder.Frames[0].Metadata != null)
{
// Get a clone copy of the metadata
BitmapMetadata sourceMetadata = sourceDecoder.Frames[0].Metadata.Clone() as BitmapMetadata; // Open the temp file
// modify values
sourceMetadata.SetQuery("/app1/ifd/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/app1/ifd/exif/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/xmp/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x100}",Width); // Image Width int 32
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x101}", Height); // Image Height int32
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9b}", sXPTitle); //XPTitle int 16u
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9f}", sXPSubject); // XPSubject int 16u
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9c}", sXPComment); // XPComment int 16u
}
... code to set metadata in Destfile
}
}
However, I get a Type Mismatch error when any of the SetQuery call are made after adding the padding. For the first call to set ImageWidth, i have tried casting the input int parameter Width to uint, long and string and also creating a 2-Byte array. I have alalso tried casting sXPTitle to a Byte array without success. What types does SetQuery expect for its second argument for the didifferent EXIF tags? (I have added the types as shown in the EXIF tags list on the Exiftool web page EXIF Tags as comments.
Continue reading...
public void CopyAndSetMetadata(string sourceFile, string destFile, string sXPTitle, string sXPSubject,
string sXPComment, int Width, int Height)
{
uint paddingAmount = 4096;
/
using (Stream sourceStream = System.IO.File.Open(sourceFile, FileMode.Open, FileAccess.Read))
{
BitmapDecoder sourceDecoder = BitmapDecoder.Create(sourceStream, createOptions, BitmapCacheOption.None); // Check source is has valid frames
if (sourceDecoder.Frames[0] != null && sourceDecoder.Frames[0].Metadata != null)
{
// Get a clone copy of the metadata
BitmapMetadata sourceMetadata = sourceDecoder.Frames[0].Metadata.Clone() as BitmapMetadata; // Open the temp file
// modify values
sourceMetadata.SetQuery("/app1/ifd/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/app1/ifd/exif/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/xmp/PaddingSchemaadding", paddingAmount);
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x100}",Width); // Image Width int 32
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x101}", Height); // Image Height int32
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9b}", sXPTitle); //XPTitle int 16u
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9f}", sXPSubject); // XPSubject int 16u
sourceMetadata.SetQuery("/app1/ifd/exif/{uint=0x9c9c}", sXPComment); // XPComment int 16u
}
... code to set metadata in Destfile
}
}
However, I get a Type Mismatch error when any of the SetQuery call are made after adding the padding. For the first call to set ImageWidth, i have tried casting the input int parameter Width to uint, long and string and also creating a 2-Byte array. I have alalso tried casting sXPTitle to a Byte array without success. What types does SetQuery expect for its second argument for the didifferent EXIF tags? (I have added the types as shown in the EXIF tags list on the Exiftool web page EXIF Tags as comments.
Continue reading...