将多张图像保存到相机胶卷中,仅保存了几张
我试图将一些图像保存到相机胶卷中,所有图像都在一个数组中。
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 循环,
我用 8 个图像进行了测试,数组显示的计数为 8,所以很好。
当我尝试保存图像时,它会出现在控制台中。
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
在我尝试的 8 张图像中,只有 5 张出现在相机胶卷中。
任何帮助都会很棒。 谢谢 :)
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);
}
}
because i dont know how many images there can be i use a while loop
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
Out of the 8 images im trying, only 5 show up in the camera roll.
Any help would be great.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么要调用
[copyOfImages removeLastObject]
?每次你经历那个外观时,你都会破坏最后一个物体,这很奇怪,因为你还没有将它添加到卷中。把那条线拿出来看看你看起来是否有效。
另外,不要使用 for 循环,而是使用以下模式:
这将枚举数组中的对象,并在到达末尾时停止。执行此操作时请确保不要修改数组。
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.
Also, rather than using a for loop, use the following pattern:
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.
我遇到了同样的问题,我通过确保按顺序保存图像来解决它。我认为可能存在某种竞争条件。
基本上,我做了:
然后在
image:didFinishSavingWithError:contextInfo:
中,我增加currentIndex
并尝试下一个图像(如果还有剩余)。到目前为止,这对我在所有情况下都有效。
I had this same issue and I resolved it by ensuring that the images are saved sequentially. I think there may be some kind of race condition going on.
Basically, I did:
Then in
image:didFinishSavingWithError:contextInfo:
, I incrementcurrentIndex
and try the next image, if there are any left.This has worked for me in every case so far.
我有同样的问题。无论我向共享 ActivityController 添加多少图片,最多只能保存 5 张。
我发现问题是发送真实的 UIImage 而不是 URL:
I had the same exact problem. No matter how much pictures i added to the share activityController, maximum of 5 were saved.
i have found that the problem was to send the real UIImage and not URL:
为了扩展 Bill 的答案,
UIImageWriteToSavedPhotosAlbum
似乎在某个未知线程上异步写入 - 但它一次可以写入的图像数量也存在一些隐藏的限制。如果深入挖掘,您甚至可以找出write busy
类型的错误。这里有更多信息:
Objective-C: UIImageWriteToSavedPhotosAlbum() + asynchronous = issues
我也同意比尔的观点,序列化你的写入是唯一合理/可靠的答案
我见过。
To expand on Bill's answer,
UIImageWriteToSavedPhotosAlbum
seems to do its writing on some unknown thread asynchronously - but also there is some hidden limit to the number of images it can write at once. You can even tease outwrite busy
-type errors if you dig in deep.Tons more info here:
Objective-C: UIImageWriteToSavedPhotosAlbum() + asynchronous = problems
I also agree with Bill that serializing your writes is the only reasonable/reliable answer
I have seen.