根据图片编码判断图片是jpeg, 还是png
func loadImage() {
let url = URL(fileURLWithPath: "/Users/CC/Desktop/Project/FindLoveiOS/FindLove/Profile/111")
do{
let data = try Data(contentsOf: url)
contentTypeForImageData(data: data)
} catch{
print(error)
}
}
func contentTypeForImageData(data: Data) {
var c : uint_fast8_t = 0
data.copyBytes(to: &c, count: 1)
switch c {
case 0xFF:
print("jpeg")
case 0x89:
print("png")
case 0x47:
print("gif")
case 0x49:
print("tiff")
default:
print("其他格式")
}
}