当我在Xcode中将一些图像文件(仅限PNG格式)复制到我的应用程序中时,图像的大小是否会改变?
或者,如何检查xcode中PNG图像的大小?
提前致谢!
答案 0 :(得分:6)
以下是如何以字节为单位打印大小:
UIImage *myImage = [UIImage imageNamed:@"xxx.png"];
NSLog(@"MyImage size in bytes:%i",[UIImagePNGRepresentation(myImage) length]);
答案 1 :(得分:1)
PNG文件保持不变。它们在构建时用pngcrush压缩。您可以右键单击.app结果,查看包内容以查看图像的最终文件大小。
或者,如果您不是在谈论文件大小,而是像素大小,那么您可以将图像加载到UIImage中并查询其“大小”属性。
答案 2 :(得分:1)
您创建一个UIImageView,然后打印新UIImageView的框架
UIImageView imageView = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithData:/*image path */];
NSLog(@"photoLoaderDidLoad: self.frame %@",NSStringFromCGRect(imageView.frame));
答案 3 :(得分:0)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editInfo{
UIImage *image=[editInfo valueForKey:UIImagePickerControllerOriginalImage];
NSURL *imageURL=[editInfo valueForKey:UIImagePickerControllerReferenceURL];
__block long long realSize;
ALAssetsLibraryAssetForURLResultBlock resultBlock=^(ALAsset *asset)
{
ALAssetRepresentation *representation=[asset defaultRepresentation];
realSize=[representation size];
};
ALAssetsLibraryAccessFailureBlock failureBlock=^(NSError *error)
{
NSLog(@"%@", [error localizedDescription]);
};
if(imageURL)
{
ALAssetsLibrary *assetsLibrary=[[[ALAssetsLibrary alloc] init] autorelease];
[assetsLibrary assetForURL:imageURL resultBlock:resultBlock failureBlock:failureBlock];
}
}