我刚接触Xcode (使用4.3),不确定如何将图像保存到设备的相机胶卷中。到目前为止,我所做的一切只是为按钮设置了一个IBAction来保存图像。我可以使用什么库方法或函数将图像保存到用户的相机胶卷中?
发布于 2012-06-21 11:19:16
您可以使用UIImageWriteToSavedPhotosAlbum()
函数。
//Let's say the image you want to save is in a UIImage called "imageToBeSaved"
UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);
编辑:
//ViewController.m
- (IBAction)onClickSavePhoto:(id)sender{
UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);
}
发布于 2015-05-20 05:32:58
作为参考,您可以使用类似的方式保存视频:
UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);
您可能希望保存视频以上载到Instagram,例如:
// 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];
}
发布于 2019-06-13 23:34:32
将图像保存在Swift 4的照片库中
在info.plist中添加“隐私-图片库添加使用说明”
然后使用以下代码保存图像
UIImageWriteToSavedPhotosAlbum(imageView.image!, nil, nil, nil)
https://stackoverflow.com/questions/11131050
复制相似问题