当我尝试对 1,000 多张图片进行排序时,为什么我的代码会出现这些错误。尽管它可以完美地处理 5 张图片。
A first chance exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
源代码
Private Function FindDateTaken(ByVal strPicture As String) As String
FindDateTaken = Nothing
Try
Const DATE_TAKEN As Integer = &H9003
Dim dateTaken As String = ""
Using img As Image = Image.FromFile(strPicture)
If img.PropertyIdList.Contains(DATE_TAKEN) Then
Dim pitem As Imaging.PropertyItem = img.GetPropertyItem(DATE_TAKEN)
dateTaken = System.Text.Encoding.UTF8.GetString(pitem.Value, 0, pitem.Value.Length)
End If
End Using
Return dateTaken
Catch ex As Exception
lblError.Text = ex.Message
End Try
End Function
最佳答案
我很确定您在立即窗口中看到了这些消息,这可能是因为默认情况下您在工具 - 选项... - 调试 - 常规中设置了选项将所有输出窗口文本重定向到立即窗口。这就是为什么当您在立即窗口中右键单击时,您看不到任何禁用消息的选项。它是输出窗口文本,因此您需要在输出窗口中设置它。所以只需打开输出窗口,右键单击并从上下文菜单中取消选中异常消息
关于vb.net - 查找内存不足的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22441135/