I have a .png file in my resources folder.(actual size is 411 KB) When I convert the uiimage to nsdata and try accessing length property, it gives me wrong value.
Code...
UIImage *image = [UIImage imageNamed:@"sample.png"];
NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)];
int imageSize = imgData.length;
NSLog(@"Image size in KB is %d",imageSize/1024); //-------- returns 631 KB
Please let me know if there is any other property which helps..
So here is my requirement.... I want to know the size of the image I pick from uimagepicker. The exact size of the image when I see it in the finder and the size which gets returned to me after picking it from the library is totally different... Is there any other property which can be used instead of length?
You are converting a png to a jpeg, and so different file size should be expected.
If you wish to get the file-size of the original, png image, do the following.
NSString *path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"png"];
NSData *rawData = [NSData dataWithContentsOfFile:path];
NSLog(@"%d", rawData.length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With