0

我必须通过一个按钮操作将一组图像保存到照片库。

for (j=85; j<100; j++)
       {
           UIImage *saveImage=[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",j]];
           UIImageWriteToSavedPhotosAlbum(saveImage,self,nil,nil);
       }

我使用上面的代码。图像名称以 85.png 开头并以 100.png 结尾。它会保存 4 或 5 张图像,然后在输出窗口中显示一些行,如下所示

-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

谁能解决这个问题?

4

1 回答 1

0

延迟一段时间后调用您的 Save 方法。图像需要一些时间才能保存在照片库中。当您连续保存多个图像时,处理覆盖和保存图像的方法不起作用。

因此,每张图像至少延迟 0.5 秒。我在我的情况下使用了这个,见下面的方法......

先声明

NSInteger frameCount; 
NSTimer pauseTimer;

全球范围内。并取一个方法名

-(void)startTimer;

现在在您的保存按钮上单击调用此方法

-(void)yourSaveButtonClick:(id)Sender
{
    [self startTimer];
}

-(void)startTimer
{
    frameCount = 85;
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(myFunctionForSaveToPhoneLibrary) userInfo:nil repeats:YES];

}

-(void)myFunctionForSaveToPhoneLibrary
{

UIImage *saveImage=[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",frameCount]];
UIImageWriteToSavedPhotosAlbum(saveImage,self,nil,nil);

frameCount++;
    if(frameCount>=100)
    {
     [pauseTimer invalidate];
     NSLog(@"Images are saved successfully");
    }
}

它会工作.....谢谢!

于 2012-06-13T14:16:17.583 回答