【发布时间】:2014-11-20 21:21:30
【问题描述】:
我有以下功能可以读取 .jpg 文件的录制日期:
Public Shared Function GetRecordingDateOfPhoto(pathOfPhoto As String) As DateTime
If Not IO.File.Exists(pathOfPhoto) Then
Throw New FileNotFoundException
End If
Dim bitmapSource As BitmapSource = BitmapFrame.Create(New Uri(pathOfPhoto, UriKind.Relative))
Dim bitmapMetadata As BitmapMetadata = TryCast(bitmapSource.Metadata, BitmapMetadata)
Dim result As DateTime
If DateTime.TryParse(bitmapMetadata.DateTaken, result) Then
Return result
Else
Throw New FormatException
End If
End Function
这个函数返回正确的日期,但是当我做这样的事情时
dim dateOfPhoto as Date = GetRecordingDateOfPhoto("foo.jpg")
My.Computer.FileSystem.MoveFile("foo.jpg", "bar.jpg")
然后我从 MoveFile(...) 中得到一个异常:IOException(“进程无法访问文件,因为它正被另一个进程使用”)
为了避免这个异常,我必须在 GetRecordingDateOfPhoto(...) 函数中准确地更改什么(可能是使用/结束使用?)?
非常感谢。
【问题讨论】:
标签: vb.net jpeg exif ioexception