app ios 删除相册图片
2016-12-29 15:51:13 hanpeng4808 阅读数 175
当app获取手机相册的图片之后如何调回到原来的界面,而不是重新打开APP

2015-11-25 18:53:34 CloverZhu 阅读数 357

首先导入两个协议 

UIImagePickerControllerDelegate

UINavigationControllerDelegate



实现下面两个方法 

-(void)takePhoto//打开相机

{

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc]init];

        picker.delegate = self;

        picker.allowsEditing = YES;

        picker.sourceType = sourceType;

        [self presentViewController:picker animated:YES completion:nil];

    }

}


-(void)localPhoto//本地相册

{

    UIImagePickerController *picker = [[UIImagePickerController alloc]init];

    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    picker.delegate = self;

    picker.allowsEditing = YES;

    [self presentViewController:picker animated:YES completion:nil];

}


调用上面两个方法即可访问相机和相册


下面方法 获取 你选中的照片 或者 你拍下的照片

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

NSString *type = [info objectForKey:UIImagePickerControllerMediaType];

    if ([type isEqualToString:@"public.image"]) {

        //      把图片转化为NSData

        UIImage *image = info[UIImagePickerControllerEditedImage];

        NSData *data = UIImageJPEGRepresentation(image, 0.1);

    

       _userHead.image = image;

}

}


这样就可以把你的一个UIImageView设置为你刚拍的或者选择的照片了


2016-05-18 16:59:57 wsk_123_123 阅读数 4277

app有一个新功能是在app中删除相册的照片。  8之前还是AssetsLibary处理

iOS 8+通过Photos.framework #import <Photos/Photos.h> 

1.添加图片

  //首先获取相册的集合
    PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
    //对获取到集合进行遍历    
    [collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        PHAssetCollection *assetCollection = obj;
    //Camera Roll是我们写入照片的相册
    if ([assetCollection.localizedTitle isEqualToString:@"Camera Roll"])  {
            [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
      //请求创建一个Asset             
       PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"pet"]];
      //请求编辑相册              
       PHAssetCollectionChangeRequest *collectonRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
      //为Asset创建一个占位符,放到相册编辑请求中
       PHObjectPlaceholder *placeHolder = [assetRequest placeholderForCreatedAsset ];
      //相册中添加照片
                [collectonRequest addAssets:@[placeHolder]];
            } completionHandler:^(BOOL success, NSError *error) {
                NSLog(@"Error:%@", error);
            }];
       }
      }];


2.删除最后一张图片

  PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
    [collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        PHAssetCollection *assetCollection = obj;
        if ([assetCollection.localizedTitle isEqualToString:@"Camera Roll"])  {
            PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:[PHFetchOptions new]];
            [assetResult enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
               [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                   //获取相册的最后一张照片
                   if (idx == [assetResult count] - 1) {
                       [PHAssetChangeRequest deleteAssets:@[obj]];
                   }
               } completionHandler:^(BOOL success, NSError *error) {
                   NSLog(@"Error: %@", error);
               }];
            }];
        }
    }];

3.删除选中的图片


//    NSURL *url= [info objectForKey:UIImagePickerControllerReferenceURL];   
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
    PHAsset *asset = [result lastObject];
    
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [PHAssetChangeRequest deleteAssets:@[asset]];
    } completionHandler:^(BOOL success, NSError *error) {
                 NSLog(@"Error: %@", error);
                 }];


2016-09-27 14:26:15 iteye_18766 阅读数 88

iOS APP删除系统相册中选中的图片

http://blog.csdn.net/wsk_123_123/article/details/51445418

 

app有一个新功能是在app中删除相册的照片。  8之前还是AssetsLibary处理

iOS 8+通过Photos.framework #import <Photos/Photos.h> 

1.添加图片

  //首先获取相册的集合
    PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
    //对获取到集合进行遍历    
    [collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        PHAssetCollection *assetCollection = obj;
    //Camera Roll是我们写入照片的相册
    if ([assetCollection.localizedTitle isEqualToString:@"Camera Roll"])  {
            [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
      //请求创建一个Asset             
       PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"pet"]];
      //请求编辑相册              
       PHAssetCollectionChangeRequest *collectonRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
      //为Asset创建一个占位符,放到相册编辑请求中
       PHObjectPlaceholder *placeHolder = [assetRequest placeholderForCreatedAsset ];
      //相册中添加照片
                [collectonRequest addAssets:@[placeHolder]];
            } completionHandler:^(BOOL success, NSError *error) {
                NSLog(@"Error:%@", error);
            }];
       }
      }];

 

2.删除最后一张图片

  PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
    [collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        PHAssetCollection *assetCollection = obj;
        if ([assetCollection.localizedTitle isEqualToString:@"Camera Roll"])  {
            PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:[PHFetchOptions new]];
            [assetResult enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
               [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                   //获取相册的最后一张照片
                   if (idx == [assetResult count] - 1) {
                       [PHAssetChangeRequest deleteAssets:@[obj]];
                   }
               } completionHandler:^(BOOL success, NSError *error) {
                   NSLog(@"Error: %@", error);
               }];
            }];
        }
    }];

 

3.删除选中的图片

//    NSURL *url= [info objectForKey:UIImagePickerControllerReferenceURL];   
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
    PHAsset *asset = [result lastObject];
    
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        [PHAssetChangeRequest deleteAssets:@[asset]];
    } completionHandler:^(BOOL success, NSError *error) {
                 NSLog(@"Error: %@", error);
                 }];

 

2018-07-23 17:21:00 weixin_34067980 阅读数 32

#pragma mark - 保存图片和视频到相册

- (void)saveImageToAlbum:(UIImage*)image

{

    if(image)

    {

        UIImageWriteToSavedPhotosAlbum(image,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),nil);

    }

}

//保存完成后调用的方法

- (void) savedPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo: (void*)contextInfo {

    if(error) {

        NSLog(@"保存图片出错%@", error.localizedDescription);

    }

    else{

        NSLog(@"保存图片成功");

    }

}

//videoPath为视频下载到本地之后的本地路径

- (void)saveVideoToAlbum:(NSString*)videoPath

{

    if(videoPath) {

        BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath);

        if(compatible)

        {

            //保存相册核心代码

            UISaveVideoAtPathToSavedPhotosAlbum(videoPath,self,@selector(savedVideoPhotoImage:didFinishSavingWithError:contextInfo:),nil);

        }

    }

}

//保存视频完成之后的回调

- (void)savedVideoPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo: (void*)contextInfo {

    if(error) {

        NSLog(@"保存视频失败%@", error.localizedDescription);

    }

    else{

        NSLog(@"保存视频成功");

    }

}

ios关于APP的删除

阅读数 1395

iOS App图片的处理

阅读数 383

iOS提取App图片

阅读数 651

没有更多推荐了,返回首页