Sohan
Sohan

Reputation: 1287

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 of my PNG image within xcode?

Thanks in advance!

Upvotes: 0

Views: 8171

Answers (4)

Darkngs
Darkngs

Reputation: 6459

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

Upvotes: 0

Cocoanetics
Cocoanetics

Reputation: 8247

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.

Upvotes: 1

Cyprian
Cyprian

Reputation: 9453

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]);

Upvotes: 6

gsempe
gsempe

Reputation: 5499

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));

Upvotes: 1

Related Questions