Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save and reload image using ALAsset?
    primarykey
    data
    text
    <p>I'm writing an app that lets users take Photos and assign them to a Device. For this I need to be able to store the URL of the taken Picture and reload the Picture afterwards. </p> <p>I know there have been several discussions on that, but strangely none of the Ansers helped me...</p> <p>So here's my Code for saving an Image:</p> <pre><code>- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init]; UIImage * image; // Request to save Image if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) { image = [info objectForKey:UIImagePickerControllerEditedImage]; [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL * assertURL, NSError * error){ if (error) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"PictureSaveErrorTitle", @"Title if saving picture fails") message:NSLocalizedString(@"PictureSaveErrorMessage", @"Message if saving picture fails") delegate:nil cancelButtonTitle:NSLocalizedString(@"PictureSaveErrorOK", @"OK if saving picture fails") otherButtonTitles:nil]; [alert show]; } else { [self setUserImage:[assertURL absoluteString]]; [imageOfDevice setImage:image]; } }]; } else { image = [info objectForKey:UIImagePickerControllerOriginalImage]; [self setUserImage:[[info valueForKey:UIImagePickerControllerReferenceURL] path]]; } [self dismissModalViewControllerAnimated:YES]; } </code></pre> <p>And this is for reloading the Image:</p> <pre><code>if (userImage != nil) { ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init]; [library assetForURL:[NSURL fileURLWithPath:userImage] resultBlock:^(ALAsset * asset){ [imageOfDevice setImage:[UIImage imageWithCGImage:[asset thumbnail]]]; } failureBlock:^(NSError * error){ NSLog(@"cannot get image - %@", [error localizedDescription]); }]; } </code></pre> <p>Does anybody see any fault?</p> <p>Thanks for helping,</p> <p>sensslen</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload