ownerblood

导航

 

- (int)isJPEGValid:(NSData *)jpeg {
    if ([jpeg length] < 4) return 1;
    const unsigned char * bytes = (const unsigned char *)[jpeg bytes];
    if (bytes[0] != 0xFF || bytes[1] != 0xD8) return 2;
    if (bytes[[jpeg length] - 2] != 0xFF ||
        bytes[[jpeg length] - 1] != 0xD9) return 3;
    return 0;
}

posted on 2012-07-31 16:07  ownerblood  阅读(1977)  评论(0)    收藏  举报