开发者

check the size of image in Xcode

When i copy some image files (PNG format only) into my app in Xcode, is the size of the image altered?

Alternately, how can i check the size o开发者_JAVA技巧f my PNG image within xcode?

Thanks in advance!


Here is how you can print the size in bytes:

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

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


You create an UIImageView and then you print the frame of your new UIImageView

UIImageView imageView = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithData:/*image path */];
NSLog(@"photoLoaderDidLoad: self.frame %@",NSStringFromCGRect(imageView.frame));


PNG files are unchanged when you add them to your Xcode project. They are compressed with pngcrush at time of build. You can right-click on your .app result, and look at the package contents to see the final file sizes of the images.

Or if you are not talking about file size, but pixel size then you can load the image into a UIImage and query its "size" property.


- (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];
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜