I took a 13.3 MB image and added it to Xcode. I know that when compiling, Xcode performs some tricks to reduce the file size. I did this to check how large the image was, after converting to data:
UIImage *image = [UIImage imageNamed:@"image.jpg"]; NSData *data = UIImageJPEGRepresentation(image, 1.0); NSLog(@"length: %i", data.length);
The length I received was 26758066 . If it is in bytes, then it reads to me as 26.7MB. How suddenly does the image appear? Is there any other way to get an image in the form of data without going through UIImage first?
EDIT: Further testing shows that this works, and outputs a data length of ~ 13.3 MB - the expected amount:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"]; NSData *data = [NSData dataWithContentsOfFile:filePath]; NSLog(@"length: %i", data.length);
ios objective-c iphone uiimage nsdata
Andrew
source share