Last post Dec 07, 2008 02:31 PM by sharepointukltd
Dec 07, 2008 02:31 PM|sharepointukltd|LINK
How to Read or Set JPG EXIF meta data, Title, Author, Comments, Subject ect from ASP.NET c#.
I have just completed a project that needed to grab the Title, Author, Comments ect form the JPG Meta Data (Knowm as EXIF (i think)).
What a mind field of crap for someting so abvious i think..
So here is what i had to do to get it working.
Use the System.Windows.Media.Imaging; name space and use the BitmapSource and BitmapMetadata to access the JPG's EXIF properties.
There are other ASP.NET ways to do it, but trust me, it is like loads of hassell.
Firstly you have to add System.Windows.Media.Imaging; to your web pages code behinde file.
To MAke this namespace avaiable you have to add referances to assemblies in your app.
read this post on what to add and how to do this.
Once you have doe this it is easy from here on in
// Open up your images and assign down to BitmapMetadata. Thats it.
FileStream fs = new FileStream(Server.MapPath("myjpg.jpg"), FileMode.Open, FileAccess.Read, FileShare.Read);
BitmapSource img = BitmapFrame.Create(fs);
BitmapMetadata meta = (BitmapMetadata)img.Metadata;
// appy your formating to page UI from here on in.
_title.Text = meta.Title;
_comments.Text = meta.Comment;
// just type (meta.(intele sense kicks in to show you the rest))
(ps i did get one error after i done the above post and I made up me page and run it. But it gave me the line of code i needed in the error page (had to paste into the web.config file) and all way ok).
Keywords & Author FIELDS
The keyword fields are in and arrary just like the author fields.
string keywordHolder = null;
foreach (string KWString in meta.Keywords)
keywordHolder += KWString
_keywords.Text = keywordHolder;
Hope this helps cos i had right hassell getting this working and there seem to be so much half backed soloutions to this.
But once you get the hang of it it is very easy from here on in and the great thing is your now using the presentation.core in asp.net.
You got to love .net....