Change imges metadata wich C# assembly


The goal is to add some data to the meta data of jpg and png images.

I have working code(using dotnet) to do this for jpg images, but it does not work for png(because the lack of available properties).
So, searching the net and I have found this:

As author states:
"The CompactExifLib library consists of one single .cs file. Therefore, it is very easy to use the library, just add the file ExifData.cs to your project and insert the namespace CompactExifLib with a using command. "

I’ve downloaded the files, but when I add the c# code to maxscript I have an error:

StringStream:"Error:CS1010 Line:66 Column:68 Newline in constant
Error:CS1012 Line:66 Column:68 Too many characters in character literal

Putting the c# code here:
Gives this:
Run-time exception (line -1): Execution time limit was exceeded
Stack Trace:
[DotNetFiddle.Infrastructure.LimitExceededException: Execution time limit was exceeded]

Putting it here:
and here:
error CS5001: Program does not contain a static 'Main' method suitable for an entry point

The c# code is 4000+ lines, so here is the maxscript:

Can this c# code be used directly inside a maxscrtipt?


Author states that it

  • Works with many .NET versions from .NET Framework 4.0

but this is simply not true. He’s seemingly in love with out parameters and I had to fix a LOT of these. Didn’t test the code of course, but at least it compiles now. (24.2 KB) (31.4 KB)

did a quick test and it works

	var f = @"C:\Users\User\Documents\tmp.jpg";
	var d = new CompactExifLib.ExifData( f );
	d.SetGpsLatitude( CompactExifLib.GeoCoordinate.FromDecimal( 12.3m, true ) );
	d.SetGpsLongitude( CompactExifLib.GeoCoordinate.FromDecimal( 45.6m, true ) );
	d.Save( f );


Thank you, Serejah!

When I try to compile the c# code inside maxscript I have the same error:
StringStream:"Error:CS1010 Line:66 Column:68 Newline in constant
Error:CS1012 Line:66 Column:68 Too many characters in character literal

When I load the dll you provided - no errors, but this:

CompactExifLib.ExifData( f )

has no option to load the file. Or I am doing something wrong.

d = dotnetClass "CompactExifLib.ExifData"
showMethods d

The result is:

.[static]<CompactExifLib.ExifTag>ComposeTagSpec <CompactExifLib.ExifIfd>Ifd <CompactExifLib.ExifTagId>TagId
.[static]<System.Boolean>Equals <System.Object>objA <System.Object>objB
.[static]<CompactExifLib.ExifIfd>ExtractIfd <CompactExifLib.ExifTag>TagSpec
.[static]<CompactExifLib.ExifTagId>ExtractTagId <CompactExifLib.ExifTag>TagSpec
.[static]<System.Int32>GetTagByteCount <CompactExifLib.ExifTagType>TagType <System.Int32>ValueCount
.[static]<System.Boolean>ReferenceEquals <System.Object>objA <System.Object>objB

Can you check if a Comments section can be added to a PNG file using c# only(like your example above). What I need is a way to add some string data to the meta data of the PNG file which then can be seen when the user right click the png file and select Properties - Details tab.


means instance of the class i.e. dotnetobject "CompactExifLib.ExifData" f load_options

as you can see mxs expects extra arg which is optional in c# constructor

CompactExifLib.ExifData <System.IO.Stream>ImageStream <CompactExifLib.ExifLoadOptions>Options
CompactExifLib.ExifData <System.String>FileNameWithPath <CompactExifLib.ExifLoadOptions>Options

just need to escape backslash when you compile it from mxs
int BackslashPosition = SourceFileNameWithPath.LastIndexOf('\\\\');

creating it from mxs is tricky, since mxs doesn’t recognize c# optional args.
I don’t have any .png with metadata so can’t test it. It worked well with jpegs.

dotnet.showconstructors (dotNetClass "CompactExifLib.ExifData")
load_options = (dotnetclass "system.enum").ToObject (dotnetclass "CompactExifLib.ExifLoadOptions") 0	
exif = dotNetObject "CompactExifLib.ExifData" @"C:\Users\User\Documents\test.png" load_options

exif.SetTagValue (dotnetclass "CompactExifLib.ExifTag").IsoSpeed "777" (dotnetclass "CompactExifLib.StrCoding").Utf8
save_options = (dotnetclass "system.enum").ToObject (dotnetclass "CompactExifLib.ExifSaveOptions") 0
exif.Save @"C:\Users\User\Documents\test.png" save_options

just tried it on jpg/png and nothing changed, ISO has no value set. I didn’t read how to use it proper way, so that’s expected

but with comments it worked with jpg, and failed with png
exif.SetTagValue (dotnetclass "CompactExifLib.ExifTag").UserComment "-- 777 --" (dotnetclass "CompactExifLib.StrCoding").Utf8
in case none of it will work with .png check out BitmapMetadata.SetQuery method

ps. the demo app that comes with the sources doesn’t support loading .png images :slight_smile:


Thank you, Serejah!
Works with jpg, do not work with png. It seems that this dll can only update existing property, but can’t add a new one.


It could be me breaking something while fixing the sources as well :slight_smile:
Maybe it is worth looking for another library for this kind of stuff