Objective-C ,ios,iphone开发基础:ios判断图片为png还是jpg或者jepg
static inline NSPUIImageType NSPUIImageTypeFromData(NSData *imageData) {
    if (imageData.length > 4) {
        const unsigned char * bytes = [imageData bytes];

        if (bytes[0] == 0xff &&
            bytes[1] == 0xd8 &&
            bytes[2] == 0xff)
        {
            return NSPUIImageType_JPEG;
        }

        if (bytes[0] == 0x89 &&
            bytes[1] == 0x50 &&
            bytes[2] == 0x4e &&
            bytes[3] == 0x47)
        {
            return NSPUIImageType_PNG;
        }
    }

    return NSPUIImageType_Unknown;
}

 

posted on 2015-06-03 22:55  pTrack  阅读(998)  评论(0)    收藏  举报