我想从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];
}在这里,我正在计算的图像大小是不正确的,图像库中的图像大小与我正在计算的图像大小不同。在选择图片之前,我想知道图片的大小,有人能事先帮我吗?
发布于 2011-06-21 17:22:08
Yo可以以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,直到您到达所需的单元为止。
https://stackoverflow.com/questions/6428191
复制相似问题