简体   繁体   English

如何在iPhone应用程序中将图像集保存到相册

[英]How to save set of images to photo gallery in iphone app

I have to save some set of images to photo gallery in one button action. 我必须通过一个按钮将一组图像保存到照片库中。

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

I use the above code.image name starts with 85.png and ends with 100.png.It saves 4 or 5 images afterthat it shows some lines in output window as follows 我使用上面的代码.image名称以85.png开头并以100.png结尾,然后保存4或5张图像,然后在输出窗口中显示一些行,如下所示

-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

could anyone fix this problem? 谁能解决这个问题?

Call Your Save method after some time delay. 一段时间后,调用Save方法。 The image takes sometime to save in photo gallery. 该图像需要花费一些时间才能保存在照片库中。 And when you save multiple images continuously then processing overwrites and method of saving image doesn't work. 而且,当您连续保存多个图像时,处理覆盖和保存图像的方法将不起作用。

So, delay at least 0.5 second for each image. 因此,每个图像至少延迟0.5秒。 I used this in my case see below method... 我在我的情况下使用此方法,请参见以下方法...

first declare 首先声明

NSInteger frameCount; 
NSTimer pauseTimer;

globally. 全球。 and make a method name 并命名一个方法

-(void)startTimer;

now on your save button click call this method 现在在您的保存按钮上单击调用此方法

-(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");
    }
}

it will Work ..... Thank You!! 它会工作.....谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM