图像URL保存 [英] Image URL saving

查看:129
本文介绍了图像URL保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的项目如何工作,我有一个 UIScrollView 下面是一个按钮 addButton ,当点击重定向时你到 AGImagePickerController (对于那些不了解AGImagePickerController的人来说,它是一个多图像选择器)。然后单击图像(单个或多个图像)。当您按 DONE 时,它会将图像保存在 NSCachesDirectory 中。它将显示在 UIScrollView 中选择的图像(可以删除)。当您再次按 addButton 时,它会显示图像已选择前一段时间 checkMark

Here is how my project works, I have a UIScrollView below it is a button addButton, when clicked redirects you to the AGImagePickerController (For those who doesn't know AGImagePickerController,it is a multiple image picker). Then you clicked the images(single or multiple images). When you press DONE, it will save the images in NSCachesDirectory. It will show the image chosen in UIScrollView (Which can be deleted). When you pressed the addButton again, it will show you the image picked a while ago with a checkMark.

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

PROBLEM : When I delete the image in the UIScrollView the image that was deleted in the AGimagePickerController is still checked. Needed is when deleted in the UIScrollVIew will also be remove in the AGimagePickerController.

我想要做的是,通过 URL 保存图像,然后将其放在我的 NSCachesDirectory 所以我可以轻松加载它,但我不知道从哪里开始,因为我在整个名称中用 UIScrollView 安排我的图像。希望有人可以建议做什么。非常感谢。

What I wanted to do is, save its image by its URL then put it in a folder inside my NSCachesDirectory so I can load it easily, but I dont know where to start, since Im arranging my images in the UIScrollView by names with integers. Hope someone could suggest what to do. Thankyou Very Much.

注意:对于那些阅读过此内容的人,请评论您希望我在此处发布的代码部分,或您遇到问题的部分。谢谢你。

NOTE : To those who have read this, please comment on what part of the code you want me to post here, or the part on which your having a problem with. Thankyou again.

代码:

这是我的 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中(保留图像复选标记部分)

Then in my AGIPCAssetsController.m(Where the retaining of the image checkmark part)

- (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];

        });

    }); 
}


推荐答案

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

Just an idea and not an exact solution. On Done button action, is it possible to save the image with name as some unique property of rep. Probably [rep filename] or [rep url] can be used as image name while saving in place of @"oneSlotImages%u.png". And in loadAssets read all the images stored in cache and compare its file name against the file names of images in selectedPhotos and remove it from the selectedPhotos array if it is not present in cache.

这篇关于图像URL保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆