【问题标题】:Image URL saving图片网址保存
【发布时间】:2012-10-01 08:46:26
【问题描述】:

这是我的项目的工作方式,我有一个UIScrollView,它下面是一个按钮addButton,单击时会将您重定向到AGImagePickerController(对于那些不知道AGImagePickerController的人,它是一个多图像选择器)。然后单击图像(单个或多个图像)。当您按下DONE 时,它会将图像保存在NSCachesDirectory 中。它将显示在UIScrollView 中选择的图像(可以删除)。当您再次按下addButton 时,它会向您显示不久前的图像pickedcheckMark

问题:当我删除UIScrollView 中的图像时,AGimagePickerController 中删除的图像仍然是checked。需要的是在UIScrollVIew 中删除时也将在AGimagePickerController 中删除。

我想做的是,通过它的URL 保存它的图像,然后将它放在我的NSCachesDirectory 内的一个文件夹中,这样我就可以轻松加载它,但我不知道从哪里开始,因为我将我的图像安排在UIScrollView 名称为整数。希望有人可以建议该怎么做。非常感谢。

注意:对于阅读过本文的人,请评论您希望我在此处发布的代码的哪一部分,或者您遇到问题的部分。再次感谢您。


代码:

这是我的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];

        });

    }); 
}

【问题讨论】:

    标签: iphone objective-c ios xcode


    【解决方案1】:

    我认为因为它们都有相同的变量引用, 检查你的变量引用并比较两者,让我知道你发现了什么。

    【讨论】:

      【解决方案2】:

      只是一个想法,而不是一个确切的解决方案。在完成按钮操作上,是否可以将图像名称保存为 rep 的某个独特属性。可能[rep filename][rep url] 可以用作图像名称,同时代替@"oneSlotImages%u.png" 保存。在loadAssets 中读取存储在缓存中的所有图像,并将其文件名与selectedPhotos 中的图像文件名进行比较,如果缓存中不存在,则将其从selectedPhotos 数组中删除。

      【讨论】:

      • 我在 NSCaches 中有其他图像。所以我将它们重命名为@"oneSlotImages%u.png"
      • 信息到底是什么?是所有 selectedPhotos 的数组吗?
      猜你喜欢
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 2019-01-10
      • 2021-10-23
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多