separar secuencia renombrar porque organizar orden las fotos como carrete cargan cambiar camara borrarlas borrar album iphone ios objective-c ipad camera

renombrar - secuencia de fotos iphone



¿Cómo puedo guardar una imagen en el carrete de la cámara? (3)

Soy nuevo en Xcode (usando 4.3) y no estoy seguro de cómo guardar una imagen en el carrete de la cámara del dispositivo. Todo lo que he hecho hasta ahora es configurar un IBAction para el botón para guardar la imagen. ¿Qué método o función de biblioteca puedo usar para guardar una imagen en el rollo de la cámara del usuario?


Aquí hay una respuesta para iOS8 usando el marco de Fotos.

C objetivo:

#import <Photos/Photos.h> UIImage *snapshot = self.myImageView.image; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot]; changeRequest.creationDate = [NSDate date]; } completionHandler:^(BOOL success, NSError *error) { if (success) { NSLog(@"successfully saved"); } else { NSLog(@"error saving to photos: %@", error); } }];

Rápido:

// Swift 4.0 import Photos let snapshot: UIImage = someImage PHPhotoLibrary.shared().performChanges({ PHAssetChangeRequest.creationRequestForAsset(from: snapshot) }, completionHandler: { success, error in if success { // Saved successfully! } else if let error = error { // Save photo failed with error } else { // Save photo failed with no error } })

Aquí hay un link a la documentación de Apple.


Como referencia, puede guardar videos de manera similar:

UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);

Es posible que desee guardar un video para subirlo a Instagram, por ejemplo:

// Save video to camera roll; we can share to Instagram from there. -(void)didTapShareToInstagram:(id)sender { UISaveVideoAtPathToSavedPhotosAlbum(self.videoPath, self, @selector(video:didFinishSavingWithError:contextInfo:), (void*)CFBridgingRetain(@{@"caption" : caption})); } - (void) video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfoPtr { NSDictionary *contextInfo = CFBridgingRelease(contextInfoPtr); NSString *caption = contextInfo[@"caption"]; NSString *escapedString = [videoPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; // urlencodedString NSString *escapedCaption = [caption stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; // urlencodedString NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@", escapedString, escapedCaption]]; [[UIApplication sharedApplication] openURL:instagramURL]; }


Utiliza la función UIImageWriteToSavedPhotosAlbum() .

//Let''s say the image you want to save is in a UIImage called "imageToBeSaved" UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);

Editar:

//ViewController.m - (IBAction)onClickSavePhoto:(id)sender{ UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil); }