Get size of a UIImage (bytes length) not height and width

后端 未结 10 2100
说谎
说谎 2020-11-28 09:00

I\'m trying to get the length of a UIImage. Not the width or height of the image, but the size of the data.

10条回答
  •  萌比男神i
    2020-11-28 09:46

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

提交回复
热议问题