By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

Speed up Camera Photo Time Stamp

P: n/a
I'm writing a program for renaming my picture files, and I want to use
the picture time stamp as a prefix to the file names. I can get the
time stamp, but it is extraordinarily slow! I have about 250 pictures
in the directory. In debug mode, I can populate the names in a
listview in less than two seconds. If I add a column with the time
stamp as a string, the listview takes about 70 seconds to populate in
debug mode. I haven't made and test a release mode yet.

Does anybody know a faster way to get the time stamp information?

'---------- Extract the picture date from the picture ----------
' Return an empty string if the file does not exist or no date tag
' Returns date string in YYYY:MM:DD HH:MM:SS
Private Function GetRawDate(ByVal FileName As String) As String
Dim l_RawDate As String = ""
If File.Exists(FileName) Then
Try
Dim img As Image = Image.FromFile(FileName)
Dim i As PropertyItem
For Each i In img.PropertyItems
If (i.Id = &H9003 Or i.Id = &H9004) And i.Type = 2
Then
l_RawDate =
System.Text.Encoding.Default.GetString(i.Value, 0, i.Value.Length - 1)
Exit For
End If
Next
Catch ex As Exception
End Try
End If
Return l_RawDate
End Function

'---------- Get the date only in YY-MM-DD format ----------
' FullDate is in YYYY:MM:DD HH:MM:SS format
' Returns date string in YY-MM-DD format
Private Function GetPictureYYMMDD(ByVal FullDate As String) As
String
Dim l_YYMMDD As String = ""
If FullDate.Length >= 10 Then
l_YYMMDD = FullDate.Substring(2, 2) + "-" + _
FullDate.Substring(5, 2) + "-" + _
FullDate.Substring(8, 2)
End If
Return l_YYMMDD
End Function

'---------- Populate the listview ----------
Private Sub Populate()
Dim l_Directory As String = txtDirectory.Text

lvw.BeginUpdate()
lvw.Clear()
lblSelected.Text = "0 Selected"
If My.Computer.FileSystem.DirectoryExists(l_Directory ) = False
Then
MsgBox("Directory name is invalid.",
MsgBoxStyle.Exclamation)
Else
Dim l_File As String
Dim l_Item As ListViewItem
Dim l_FileInfo As System.IO.FileInfo
Dim s As String = ""

lvw.Columns.Add("File Name")
lvw.Columns.Add("Picture Taken")
lvw.Columns.Add("Last Edited Date")
lvw.Columns.Add("Preview")
Try
For Each l_File In
My.Computer.FileSystem.GetFiles(l_Directory)
l_Item = New ListViewItem(l_File)
l_FileInfo = New System.IO.FileInfo(l_File)
s = GetRawDate(l_File)
s = GetPictureYYMMDD(s)
l_Item.SubItems.Add(s)
lvw.Items.Add(l_Item)
Next
Catch ex As Exception
End Try
End If
lvw.EndUpdate()
End Sub

Aug 1 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Shane wrote:
I'm writing a program for renaming my picture files, and I want to use
the picture time stamp as a prefix to the file names. I can get the
time stamp, but it is extraordinarily slow! I have about 250 pictures
in the directory. In debug mode, I can populate the names in a
listview in less than two seconds. If I add a column with the time
stamp as a string, the listview takes about 70 seconds to populate in
debug mode. I haven't made and test a release mode yet.

Does anybody know a faster way to get the time stamp information?
You are reading the entire image, which includes reading the entire file
and decompressing the image into a bitmap.

You can read the metadata directly from the file instead. That of course
means that you have to read up on the format of the file to find out how
to get to the interresting parts.

Alternatively you might find someone else who has already written code
for that.

--
Göran Andersson
_____
http://www.guffa.com
Aug 1 '07 #2

P: n/a
Ok, yeah, that's pretty obvious that the image variable was the
slowing down area.

I could use a background task to update the dates in my list, but I'd
rather not.

Does anybody have faster code?

Shane

Aug 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.