您好,登錄后才能下訂單哦!
實(shí)例如下所示:
- (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(@"圖片保存成功!"); } } 此方法可以把其他來源的圖片也可保存到相冊 //當(dāng)image從相機(jī)中獲取的時(shí)候存入相冊中 //保存方法1 // UIImageWriteToSavedPhotosAlbum(img.image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL); // imageData = nil; WEAKSELF //保存方法2同時(shí)獲取保存的相片文件名 __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 把圖片保存到相冊,并獲取圖片文件名的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。