How to get Size of UIImage in Bytes in iOS 4.0+?

后端 未结 4 1164
北恋
北恋 2021-02-08 08:01

I am trying to pick an image from the photo library or from the camera.
The delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker d         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 08:38

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

提交回复
热议问题