将多个图像保存到相机胶卷,仅保存了一些 [英] Saving multiple images to camera roll, only saved a few

查看:93
本文介绍了将多个图像保存到相机胶卷,仅保存了一些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些图像保存到相机胶卷,所有图像都在一个数组中。

Im attempting to save some images to a camera roll, all the images are in a array.

    if (buttonIndex == 1) {
    int done = 0;
    NSMutableArray *copyOfImages = [[NSMutableArray alloc]initWithArray:saveImagesToArray];
    while (!done == 1){

        if (copyOfImages.count == 0) {
            done = 1;
        }
        if (copyOfImages.count > 0){
            [copyOfImages removeLastObject];
        }

    UIImage *image = [[UIImage alloc]init];
    image = [copyOfImages lastObject];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

    }

}

因为我没有我知道有多少图像可以使用while循环

because i dont know how many images there can be i use a while loop

我用8张图像测试这个,数组显示的数量是8,所以这很好。

Im testing this with 8 images, the array shows a count of 8 so thats good.

当我尝试保存图像时,这会出现在控制台中。

When i try saving the images this comes up in the console.

-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

在我尝试的8个图像中,只有5个出现在相机胶卷。

Out of the 8 images im trying, only 5 show up in the camera roll.

任何帮助都会很棒。
谢谢:)

Any help would be great. Thanks :)

推荐答案

你为什么要打电话 [copyOfImages removeLastObject]
每次你经历那种外观时你都会摧毁最后一个物体,这很奇怪,因为你尚未将它添加到卷筒中。取出那条线,看看你是否看起来有效。

Why are you calling [copyOfImages removeLastObject]? Every time you go through that look are you destroying the last object, which is strange because you haven't added it to the roll yet. Take out that line and see if you look works.

此外,不是使用for循环,而是使用以下模式:

Also, rather than using a for loop, use the following pattern:

for (id object in array) {
    // do something with object
}

这将枚举数组中的对象,当它到达结尾时停止。确保在执行此操作时不要修改数组。

This will enumerate though the objects in the array, stopping when it reaches the end. Just be sure not to modify the array while you are doing this.

这篇关于将多个图像保存到相机胶卷,仅保存了一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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