美文网首页
ios 图片和视频保存到相册

ios 图片和视频保存到相册

作者: 雪域红鹰 | 来源:发表于2024-04-02 08:50 被阅读0次

// 保存视频到相册
//path为视频下载到本地之后的本地路径

- (void)saveVideo:(NSString *)path{
    NSURL *url = [NSURL URLWithString:path];
    BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([url path]);
    if (compatible) {
            //保存相册核心代码
        UISaveVideoAtPathToSavedPhotosAlbum([url path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
    }

}

//保存视频完成之后的回调
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error == NULL) {
         NSLog(@"保存视频成功 %@",videoPath);
    }else{
        NSLog(@"保存视频失败 %@",videoPath);
    }
}

// 保存图片到相册

-(void)takePicProcess:(UIImage*)img{
    UIImage *image = img;
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

#pragma mark -- <保存到相册>
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    NSString *msg = nil ;
    if(error){
        msg = @"保存图片失败" ;
    }else{
        msg = @"保存图片成功" ;
        [self performSelectorOnMainThread:@selector(showTakePicResult) withObject:nil waitUntilDone:NO];
    }
    NSLog(@"保存图片====>%@",msg);
}

-(void)showTakePicResult{
    NSLog(@"保存图片成功");
}

相关文章

网友评论

      本文标题:ios 图片和视频保存到相册

      本文链接:https://www.haomeiwen.com/subject/evhwtjtx.html