How do I get the data from UIImagePickerControllerReferenceURL?

前端 未结 3 1857
臣服心动
臣服心动 2020-12-08 06:28

I am using ELCImagePickerController in my app and I don\'t want to save the selected fullScreenImage to my array because if i selected 40 iPad images then that is not good.

3条回答
  •  猫巷女王i
    2020-12-08 06:44

    in ELCImagePickers "Selected assets" you can do

    -(void)selectedAssets:(NSArray*)_assets {
    
    "... your code .?.?."
    
        NSMutableArray *returnArray = [[NSMutableArray alloc] init];
    
        for(ALAsset *asset in _assets) {
    
            NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
            [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];
    
    ".. any other properties you need ?"
    
            [returnArray addObject:workingDictionary];
    
        }
    }
    

    Then in your other class to save from array

    - (void) importImagesFromArray:(NSArray *)_images toFolder:(NSString *)folderPath
    {
       if ([_images count] > 0) {
    
        //... YOUR CODE HERE FOR CHECKING YOUR ARRAY...Maybe a loop or something//
        //
        //
        //
    
        //ex:
    
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        for (NSDictionary *dict in _images) {
    
    
    
            [library assetForURL:[dict objectForKey:@"UIImagePickerControllerReferenceURL"]
                     resultBlock:^(ALAsset *asset){
    
                         //You Can Use This
    
                         UIImage *theImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]
                                                                 scale:1.0
                                                           orientation:[[asset valueForProperty:@"ALAssetPropertyOrientation"] intValue]];
    
                         //[....save image blah blah blah...];
    
                         ///////////////////////////////////////////////////
                         ///////////////////////////////////////////////////
    
                         ////// OR YOU CAN USE THIS////////////////////
    
                         ALAssetRepresentation *rep = [asset defaultRepresentation];
                         Byte *buffer = (Byte*)malloc(rep.size);
                         NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
                         NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
                         [data writeToFile:[folderPath stringByAppendingPathComponent:@"Some Filename You Need To Assign"] atomically:YES];
    
    
                     }
    
                    failureBlock:^(NSError *error){
                        NSLog(@"Error saving image");
    
                    }];
    
            // Dont forget to release library
    
        }
    }
    }
    

提交回复
热议问题