imageGallery から画像を取得しました。ここで、画像のファイルサイズ (KB) について知りたいと思います。どうすればいいですか?私を案内してください。それを見つけることは可能ですか?
3693 次
3 に答える
9
はい、サイズを取得できます。次のコードを試してください。
NSData *imgData = [[NSData alloc] initWithData:UIImageJPEGRepresentation((image), 0.5)];
int imageSize = imgData.length;
NSLog(@"size of image in KB: %f ", imageSize/1024.0);
于 2013-01-09T10:23:14.783 に答える
1
これを試してください:
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);
于 2013-01-09T10:34:21.070 に答える
1
BOOL isPNG = [[yourImgPath lowercaseString] isEqualToString:@"png"];
NSData *imageData = isPNG ?
UIImagePNGRepresentation(img) :
UIImageJPEGRepresentation(img, 0);
int imageSize = imageData.length;
NSLog(@"size of image in KB: %f ", imageSize/1024.0);
于 2013-01-09T10:27:26.037 に答える