2011-06-20 52 views
0

当我在Xcode中将一些图像文件(仅限PNG格式)复制到我的应用程序中时,是否更改了图像的大小?检查Xcode中的图像大小

或者,我如何检查xcode中的PNG图像的大小?

在此先感谢!

回答

6

这里是你如何可以打印字节大小:

UIImage *myImage = [UIImage imageNamed:@"xxx.png"]; 

NSLog(@"MyImage size in bytes:%i",[UIImagePNGRepresentation(myImage) length]); 
1

将PNG文件添加到Xcode项目时,PNG文件保持不变。它们在构建时与pngcrush压缩在一起。您可以右键单击您的.app结果,然后查看软件包内容以查看图像的最终文件大小。

或者,如果您不是在讨论文件大小,而是像素大小,那么您可以将图像加载到UIImage并查询其“大小”属性。

1

您创建的UIImageView,然后打印新的UIImageView的框架

UIImageView imageView = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithData:/*image path */]; 
NSLog(@"photoLoaderDidLoad: self.frame %@",NSStringFromCGRect(imageView.frame)); 
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]; 
    } 
}