2012-06-13 82 views
0

我必須在一個按鈕操作中將一些圖像集保存到照片庫。如何在iphone應用程序中將圖像集保存到照片庫

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

我使用上面code.image名稱與85.png開始和結束與100.png.It保存4倍或5的圖像afterthat它示出了在輸出窗口中的一些行如下

-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL 

誰能解決這個問題?

回答

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

它會工作.....謝謝!!

+0

一個很好的建議,但不要指望隨機延遲。 UIImageWriteToSavedPhotosAlbum()用來告訴你它已完成的回調函數。在文檔中查找它。 – Dancreek

+0

我已經更新了我的答案,現在看看這.... – TheTiger

相關問題