nyqa

I have tried to search for this but all I have found is some C code that I don't understand.

Im using VB 2005 Visual Studio and want to extract all metadata from a jpeg. Photo taken date and time and so on.
Anyone knows how to do this


Re: Visual Basic Express Edition Read all metadata from a JPEG?

JohnWein

Search your help files for "Reading and Writing Metadata". You get the PropertyItem that you desire through the property tag.





Re: Visual Basic Express Edition Read all metadata from a JPEG?

nyqa

Like I said I don't understand the C language. And that site you linked does sure look like C to me.
But thanks for your reply tho'...


Aren't there any better site for this method in the VB language And how do I know wich tag hides behind each PropertyItem




Re: Visual Basic Express Edition Read all metadata from a JPEG?

JohnWein

Just read the English. That article will send you to the Property Tags. Loop through the PropertyItems until you find the one with the Tag that you are interested in.





Re: Visual Basic Express Edition Read all metadata from a JPEG?


Re: Visual Basic Express Edition Read all metadata from a JPEG?

nyqa

Thanks for the link. But all that code didn't make me any smart I think. I still don't get it how to extract the info.
Can some kind person write me a demo of a openfiledialog that pics an image and posts the metatags in a label or something




Re: Visual Basic Express Edition Read all metadata from a JPEG?

ssta

Look at ExifWorks.vb in the sample I pointed you to-- it comes with a sample. This code GNUed but fine for learning what you have to do. Most of the extra data on JPEGs, TIFFs and other files are encoded with EXIF information in their metadata. EXIF is the common format that you will find on an image and most digital cameras support it.

You can look at www.exif.org for the specifications and try to decode the properties yourself. Maybe someone else wants to take the time to decipher the spec. or you could just use the library I mentioned above that wraps

It might also be worth pointing out that Windows Explorer supports the display of EXIF tags but I don't think you can ask the shell to pass on that information.






Re: Visual Basic Express Edition Read all metadata from a JPEG?

nyqa

Yeah Explorer shows the data in the statusbar as default but I also don't think it can be passed on to VB.

I did take a look at ExifWorks.vb to try figuring out how the function works but I didn't manage to get it. I haven't been around VB that long to know everything there is to know to be able to understand the whole code in that file. So it's kind of hard for me to understand how it works to 100%. Sad
Any help with "translating" the ExifWorks.vb file would be appreciated.




Re: Visual Basic Express Edition Read all metadata from a JPEG?

ssta

All you have to do is a ExifWorks.vb to your project or create a dll and reference that. After you have access to the class you instantiate the class and start using it.


Sample steps using class:

1. Create a new Windows Application

2. Add ExifWorks.vb to your application

3. Add a Button, PropertyGrid and an OpenFileDialog to the Form1


4. Add the following code to the Button.Click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1Button.Click

If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

Dim ew As New ExifWorks(OpenFileDialog1.FileName)

PropertyGrid1.SelectedObject = ew

End If

End Sub







Re: Visual Basic Express Edition Read all metadata from a JPEG?

nyqa

Great, thanks mate!

Im now working on a function that converts the ew.DateTimeOriginal to a string with the date like "2th June 2007 2:24PM" but in Swedish.
Im geting it to work but I would like my function to have the year, month, date and time value in different strings.
I've started the code but I don't know how to finish it:

Public Class Form1
Label1.Text = GetPhotoTaken(year)
Label2.Text = GetPhotoTaken(month) & GetPhotoTaken(date)
Label3.Text = GetPhotoTaken(time)
End class


Module MyModule
Dim ew As New ExifWorks(Form1.OpenFileDialog1.FileName)

Public Function GetPhotoTaken

Dim PhotoYear

PhotoYear = Left(ew.DateTimeOriginal, 4)
' etc
End Function

End Module


How do I get the PhotoYear string in GetPhotoTaken(year) and so on




Re: Visual Basic Express Edition Read all metadata from a JPEG?

ssta

Here's a sample for you. Sory I don't speak Swedish but you'll get the idea:
Code Snippet

Dim ci As New System.Globalization.CultureInfo("sv-SE")

MsgBox(Now.ToString(ci.DateTimeFormat.LongDatePattern))
MsgBox(Now.ToString("yyyy-mmm-dd (ddd) HH:mm:ss", ci.DateTimeFormat))