PDA

View Full Version : .net Metafile class?


Riffmaster
03-05-2012, 11:21 AM
Has anybody made use of the .net class below using maxscript (dotNetClass "System.Drawing.Imaging.Metafile")
I am looking for a way to access the metadata stored in image files, specifically the camera data and keywords stored in image files. Just a little unsure how I would go about implementing the above class in my script.

Any suggestions would be greatly appreciated.

Thanks,

D.

lo
03-05-2012, 06:54 PM
The Imaging.Metafile class doesn't do what you think it does. It has nothing to do with image EXIF data.

I don't have any working code to share, but here is a link to give you a direction, provided you can convert the c# code to maxscript code:

http://www.developerfusion.com/article/84474/reading-writing-and-photo-metadata/

PiXeL_MoNKeY
03-05-2012, 09:10 PM
There are tools out there to do what you want like DCRaw (http://www.cybercom.net/%7Edcoffin/dcraw/) and ExifTools (http://www.sno.phy.queensu.ca/%7Ephil/exiftool/), but both are command-line tools and not dotnet libraries. ExifTools is also available as a Perl Library, but I have no idea how you would go about using that with Maxscript.

-Eric

lo
03-05-2012, 09:42 PM
A c# library:

http://www.codeproject.com/Articles/11305/EXIFextractor-library-to-extract-EXIF-information

Riffmaster
03-06-2012, 10:23 AM
Sorry after I posted I did a little research and realised that this metafile class wasn't exactly what I was looking for. Thanks lo for the links.

Here is what I have so far...

-- Bitmap stream
file=@"c:\test.jpg"
FileMode=dotNetClass "System.IO.FileMode"
FileAccess=dotNetClass "System.IO.FileAccess"
FileShare=dotNetClass "System.IO.FileShare"
BitmapStream = dotNetObject "System.IO.FileStream" file FileMode.Open FileAccess.ReadWrite FileShare.ReadWrite;

--Jpeg bitmap decoder
BitmapCreateOptions=dotNetClass "System.Windows.Media.Imaging.BitmapCreateOptions"
BitmapCacheOption=dotNetClass "System.Windows.Media.Imaging.BitmapCacheOption"
BitmapDecoder = dotNetObject "System.Windows.Media.Imaging.JpegBitmapDecoder" BitmapStream BitmapCreateOptions.PreservePixelFormat BitmapCacheOption.Default;


Show properties on the Bitmapdecoder now reveals a metadata property. I understand the metadata, in the case of a Jpeg image, is stored in Frame[0]

Jpegframe = bitmapdecoder.frames.Item[0]


However this seems to return an error


-- Runtime error: dotNet runtime exception: Specified value of type 'System.Windows.Media.Imaging.BitmapFrameDecode' must have IsFrozen set to false to modify.


Any thoughts on where I may be going wrong?

Thanks,

D.

lo
03-06-2012, 11:14 AM
I think you're still looking in the wrong place. Here's an incomplete code block to get you started:

thebmp = dotnetobject "system.drawing.bitmap" @"c:\test.jpg"
asciiCls = (dotnetClass "System.Text.Encoding").ascii
bCnv = (dotnetClass "System.BitConverter")
for item in thebmp.propertyitems do
(
local l = item.len
local v = item.value
local displayValue = case item.type of
(
1:(v)
2:(asciiCls.getString v 0 (l-1))
3:(bCnv.ToUInt16 v 0)
4:(bCnv.ToUInt32 v 0)
7:(bCnv.ToInt32 v 0)
default:(v)


)
format "ID:%\tType:%\tValue:%\n" item.id item.type displayValue
)
thebmp.dispose()

The following information will help you continue it:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.type.aspx
http://msdn.microsoft.com/en-us/library/ms534418(v=vs.85).aspx

Riffmaster
03-06-2012, 12:35 PM
Thanks Lo, looks like I was way off the mark. This seems to be closer to what I was looking for, will have a play around with this.

CGTalk Moderation
03-06-2012, 12:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.