图片url保存
这里是我的项目如何工作,我有一个UIScrollView
它下面是一个buttonaddButton
,当点击redirect到AGImagePickerController
(对于那些谁不知道AGImagePickerController,它是一个多重图像select器)。 然后,您单击图像(单个或多个图像)。 当按DONE
,它将把图像保存在NSCachesDirectory
。 它会显示在UIScrollView
select的图像(可以删除)。 当你再次按下addButton
时,它会显示前一个checkMark
的图像。
问题:当我删除UIScrollView
的图像时,在AGimagePickerController
中删除的图像仍然checked
。 需要的是在UIScrollVIew
删除的时候也会在AGimagePickerController
删除。
我想要做的是,通过它的URL
保存它的形象,然后把它放在我的NSCachesDirectory
内的文件夹,所以我可以轻松加载,但我不知道从哪里开始,因为我安排我的图像在UIScrollView
名称与整数。 希望有人可以build议做什么。 非常感谢你。
注意:对于那些已经阅读过这个内容的人,请评论你希望我在这里发布的代码的哪一部分,或者哪个部分与你有问题。 再次感谢你。
码:
这是我DONE
部分:
for (int i = 0; i < info.count; i++) { //NSLog(@"%@", [info objectAtIndex:i]); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask ,YES ); NSString *documentsDir = [paths objectAtIndex:0]; NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%u.png", i]]; ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation]; UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]]; //----resize the images image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)]; //----fix image orientation image = [image fixSlotOrientation]; NSData *imageData = UIImagePNGRepresentation(image); [imageData writeToFile:savedImagePath atomically:YES]; }
然后在我的AGIPCAssetsController.m
(其中保留图像复选checkmark
部分)
- (void)loadAssets { count = 0; [self.assets removeAllObjects]; AGIPCAssetsController *blockSelf = self; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ // Where I make an array to put the `ALAsset Url` selectedPhotos = [[NSMutableArray alloc] initWithArray:blockSelf.imagePickerController.selection]; @autoreleasepool { [blockSelf.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { // ALAssetRepresentation* representation = [result defaultRepresentation]; // NSUInteger assetindex= [blockSelf.assetsGroup numberOfAssets]; if (result == nil) { return; } AGIPCGridItem *gridItem = [[AGIPCGridItem alloc] initWithAsset:result andDelegate:blockSelf]; if(count < blockSelf.imagePickerController.selection.count) { if ( blockSelf.imagePickerController.selection != nil && [result isEqual:[selectedPhotos objectAtIndex:count]]) { gridItem.selected = YES; count++; NSLog(@" %@",result); } } [blockSelf.assets addObject:gridItem]; }]; } dispatch_async(dispatch_get_main_queue(), ^{ [blockSelf reloadData]; }); }); }
我认为他们都有相同的variables引用,检查你的variables引用和两者之间的比较,让我知道你find了什么。
只是一个想法而不是一个确切的解决scheme 在完成button操作,是否有可能保存图像的名称作为一些独特的rep
属性。 在保存@"oneSlotImages%u.png"
同时,可能会使用[rep filename]
或[rep url]
作为图像名称。 然后在loadAssets
读取存储在caching中的所有图像,并将其文件名与selectedPhotos
中图像的文件名进行比较,如果不存在于caching中,则将其从selectedPhotos
数组中移除。