我想从UIImagePickerControllerSourceTypePhotoLibrary
获取图像,在从图像库中选择图像之前,我想知道该特定图像的内存大小。我正在使用
- (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 dismissModalViewControllerAnimated:NO];
}
这里我正在计算的图像尺寸不正确,图像库中的图像尺寸究竟与我正在计算的图像尺寸不同。 我想在选择图像之前知道图像大小 谁能帮我 提前致谢
答案 0 :(得分:3)
哟可以用JPEG格式获取所选图像的大小:
UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
NSData *imageData = UIImageJPEGRepresentation(img, 1.0);
yourImgSize = [imageData length];
或PNG格式
UIImage * img = [info objectForKey:@"UIImagePickerControllerEditedImage"];
NSData *imageData = UIImagePNGRepresentation(img, 1.0);
yourImgSize = [imageData length];
修改强>
它将以字节为单位,你可以认为有用的除以1024,直到你得到你想要的单位