实际加载图像的所有智能都是由 .net 框架完成的,似乎我不应该通过检查幻数或使用这样的 hack 在我的代码中重复这一切:
Private Function IsImage(FileName as String) As Boolean
Try
Using img As New Bitmap(FileName)
End Using
Catch ex as System.ArgumentException
Return False
End Try
Return True
End Function
我是否遗漏了一些明显的东西,比如System.Drawing.IsImage(stream)
?