[Closed] .net Metafile class?
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.
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/
A c# library:
http://www.codeproject.com/Articles/11305/EXIFextractor-library-to-extract-EXIF-information
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: est.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.
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: est.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:% Type:% Value:%
" 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
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.