首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将图像保存到相机胶卷?

如何将图像保存到相机胶卷?
EN

Stack Overflow用户
提问于 2012-06-21 11:14:11
回答 3查看 89K关注 0票数 131

我刚接触Xcode (使用4.3),不确定如何将图像保存到设备的相机胶卷中。到目前为止,我所做的一切只是为按钮设置了一个IBAction来保存图像。我可以使用什么库方法或函数将图像保存到用户的相机胶卷中?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-06-21 11:19:16

您可以使用UIImageWriteToSavedPhotosAlbum()函数。

代码语言:javascript
复制
//Let's say the image you want to save is in a UIImage called "imageToBeSaved"
UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);

编辑:

代码语言:javascript
复制
//ViewController.m
- (IBAction)onClickSavePhoto:(id)sender{

    UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);
}
票数 245
EN

Stack Overflow用户

发布于 2015-05-20 05:32:58

作为参考,您可以使用类似的方式保存视频:

代码语言:javascript
复制
UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);

您可能希望保存视频以上载到Instagram,例如:

代码语言:javascript
复制
// 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];
}
票数 11
EN

Stack Overflow用户

发布于 2019-06-13 23:34:32

将图像保存在Swift 4的照片库中

在info.plist中添加“隐私-图片库添加使用说明”

然后使用以下代码保存图像

代码语言:javascript
复制
UIImageWriteToSavedPhotosAlbum(imageView.image!, nil, nil, nil)
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11131050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档