如何在ios应用程序编码中获取图像大小

如何在ios应用程序编码中获取图像大小,ios,objective-c,uiimage,nsdate,Ios,Objective C,Uiimage,Nsdate,我已从imageGallery检索到一个图像。现在我想知道图像的文件大小,以KB为单位。我该怎么做?请引导我。有可能找到它吗?是的,你可以得到它的尺寸。请尝试以下代码: NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)]; int imageSize = imgData.length; NSLog(@"size of image in KB: %f ", imageSi

我已从imageGallery检索到一个图像。现在我想知道图像的文件大小,以KB为单位。我该怎么做?请引导我。有可能找到它吗?

是的,你可以得到它的尺寸。请尝试以下代码:

NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)];
int imageSize   = imgData.length;
NSLog(@"size of image in KB: %f ", imageSize/1024.0);

是的,你可以买到这个尺寸。请尝试以下代码:

NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)];
int imageSize   = imgData.length;
NSLog(@"size of image in KB: %f ", imageSize/1024.0);
试试这个:

NSString *imagePath=[[NSBundle mainBundle]pathForResource:@"images" ofType:@"jpeg"];
UIImage *image=[[UIImage alloc]initWithContentsOfFile:imagePath];

NSError *error;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imagePath error:&error];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
NSLog(@"size of image is : %fKB ", fileSize/1024.0);
试试这个:

NSString *imagePath=[[NSBundle mainBundle]pathForResource:@"images" ofType:@"jpeg"];
UIImage *image=[[UIImage alloc]initWithContentsOfFile:imagePath];

NSError *error;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imagePath error:&error];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
NSLog(@"size of image is : %fKB ", fileSize/1024.0);

你可以找到我的NSFileManager你可以找到我的NSFileManager那是什么图像类型?是JPEG还是PNG?我在这里假设jpeg。不确定这是否有影响?嗨,Srikar,谢谢。。[imageDate length]返回以KB或字节为单位的大小?这是什么图像类型?是JPEG还是PNG?我在这里假设jpeg。不确定这是否有影响?嗨,Srikar,谢谢。。[imageDate length]返回大小(KB或字节)?