How do I get a thumbnail or saveable path from UIImagePickerController to use for a UIImageView?

前端 未结 4 1607
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 13:15

Could somebody please explain or show some sample code of how I can use get a thumbnail to be put into a UIImageView after the user selects a photo with UIImagePickerController?

4条回答
  •  清酒与你
    2021-02-03 13:26

    You can save the image you select from imagePicker into Documents Directory instaed of referencing it from the picker Here is the code you can use for saving image. Implement this method in the callback method invoked when user selects a photo from the picker

     NSFileManager   fileManager    = [NSFileManager defaultManager];
    
        NSArray*  output_PDF_paths  =  NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    
        NSString* output_PDF_documentsDirectory = [output_PDF_paths objectAtIndex:0];
        NSString* output_PDF_ABSOLUTE_PATH  = [output_PDF_documentsDirectory stringByAppendingPathComponent:@"ImageName.png"];  
    
        BOOL success_new = [UIImagePNGRepresentation(ProfilePhotoselected) writeToFile:previewPagePath atomically:YES];
    

    //Here the "ProfilePhotoselected" is the image which you get from the picker as a argument in your callabck method

提交回复
热议问题