iOS把图片保存到相册,并获取图片文件名的实例-成都快上网建站

iOS把图片保存到相册,并获取图片文件名的实例

实例如下所示:

蒙城ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
 if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
  UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
 }
}
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
 if (error) {
  DLog(@"图片保存失败!");
 }else{
  DLog(@"图片保存成功!");
 }
}
此方法可以把其他来源的图片也可保存到相册

 //当image从相机中获取的时候存入相册中
 //保存方法1
//  UIImageWriteToSavedPhotosAlbum(img.image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
//   imageData = nil;
  
  WEAKSELF
  //保存方法2同时获取保存的相片文件名
  __blockALAssetsLibrary *lib = [[ALAssetsLibraryalloc] init];
  [lib writeImageToSavedPhotosAlbum:img.image.CGImagemetadata:nilcompletionBlock:^(NSURL *assetURL,NSError *error) {
   
   ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
   {
    ALAssetRepresentation *imageRep = [imageAssetdefaultRepresentation];
    weakSelf.imageName = [NSStringstringWithFormat:@"%@",[imageRepfilename]];
    NSLog(@"[imageRep filename 1] : %@", [imageRepfilename]);
    DBLog(@"self.addressImageName照相0 = %@",weakSelf.imageName);
    commitBlock(img.image,UIImageJPEGRepresentation(img.image,0.5),self.imageName);
   };
   ALAssetsLibrary* assetslibrary = [[ALAssetsLibraryalloc] init];
   [assetslibrary assetForURL:assetURLresultBlock:resultblock failureBlock:nil];
   
   NSLog(@"assetURL = %@, error = %@", assetURL, error);
   lib = nil;
   
  }];
  
 }];

以上这篇iOS 把图片保存到相册,并获取图片文件名的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。


当前标题:iOS把图片保存到相册,并获取图片文件名的实例
本文网址:http://kswjz.com/article/poihig.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流