I need to find total size of all images inside photo library in iPhone. I have using Assets Library framework and successfully find number of images. However images are of smaller size and converting them into MB giving me wrong result. Below is the source code.
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
UIImage *image = [UIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
[self performSelectorOnMainThread:@selector(usePhotolibraryimage:) withObject:image waitUntilDone:NO];
}
}];
}
failureBlock:^(NSError *error) {
NSLog(@"%@",error.description);
}];
- (void)usePhotolibraryimage:(UIImage *)myImage{
//Do your all UI related and all stuff here
NSData *imageData = UIImageJPEGRepresentation(myImage, 0.5);
int imageSize = imageData.length/1024;
totalImageSize = totalImageSize+imageSize;
}
However while converting image into MB its showing me wrong count of all images, Please let me know what i am doing wrong.