iOS把图片保存到相册,并获取图片文件名的实例-创新互联
实例如下所示:
创新互联主要从事网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务甘德,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792- (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; }]; }];
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享标题:iOS把图片保存到相册,并获取图片文件名的实例-创新互联
转载源于:http://azwzsj.com/article/dhhsig.html