how to get the size of the image which in UIImage picker controller before choosing it?
I want to get images from UIImagePickerControllerSourceTypePhotoLibrary
, before choosing the image from image library, i want to know the memory size of that particular image . I'm using
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
size_t imageSize = CGImageGetBytesPerRow(img.CGImage) * CGImageGetHeight(img.CGImage);
printf("\n the image size is :%zd",imageSize);
[self useImage:img];
[[picker parentViewController] dismissModalViewControllerAnimated:NO];
UINavigationController* navController = self.navigationController;
UIViewController* controller = [navController.viewControllers objectAtIndex:0];
[controller开发者_如何学JAVA dismissModalViewControllerAnimated:NO];
}
here the image size which I'm calculating is incorrect, what exactly the image size in image library is different from image size I'm calculating. And i want to know the image size before picking the image Can anyone help me Thanks in advance
Yo can get size of your picked image in JPEG format like this:
UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
NSData *imageData = UIImageJPEGRepresentation(img, 1.0);
yourImgSize = [imageData length];
Or in PNG format
UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
NSData *imageData = UIImagePNGRepresentation(img, 1.0);
yourImgSize = [imageData length];
EDIT
It will be in bytes, you may consider usefull to divide by 1024 untill you get to your desired unit
精彩评论