2010-09-03 69 views
0

我的應用程序在我的iPhone上測試時出現問題。 我都合併到一個四象,並將其保存到圖片庫的方法:將應用程序保存到庫時iPhone應用程序崩潰

- (UIImage *)combineImages{ 
     UIImage *image1 = firstImgView.image; 
     UIImage *image2 = secondImgView.image; 
     UIImage *image3 = thirdImgView.image; 
     UIImage *image4 = fourthImgView.image; 

     UIGraphicsBeginImageContext(image1.size); 

     [image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; 
     [image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)]; 
     [image3 drawInRect:CGRectMake(0, 0, image3.size.width, image3.size.height)]; 
     [image4 drawInRect:CGRectMake(0, 0, image4.size.width, image4.size.height)]; 

     UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 

     return resultingImage; 
    } 
//save actual design in photo library 
- (void)savePicture{ 
    UIImage *myImage = [self combineImages]; 
    UIImageWriteToSavedPhotosAlbum(myImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), self); 
} 

//feedback if picture saving was successfull 
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { 
    NSString *message; 
    NSString *title; 
    if (!error) { 
     title = NSLocalizedString(@"Image saved", @""); 
     // message = NSLocalizedString(@"Your image was saved", @""); 
    } else { 
     title = NSLocalizedString(@"Error", @""); 
     message = [error description]; 
    } 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 
                message:message 
                delegate:nil 
              cancelButtonTitle:NSLocalizedString(@"Ok", @"") 
              otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 

當我想測試它,我得到以下錯誤:

Program received signal: 「EXC_BAD_ACCESS」. 
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.) 
warning: Cancelling call - objc code on the current thread's stack makes this unsafe. 

在模擬器它的工作原理精細。

回答

0

如果圖像總計超過1k x 1k像素,那麼我的猜測是您在設備上的內存不足。模擬器有更多的可用內存。在模擬器版本上運行內存分配工具,查看圖像和合成操作實際消耗的峯值。

+0

圖片均爲320x460。 – Crazer 2010-09-10 06:50:54

0

我的猜測是,您必須在將圖像傳遞到UIImageWriteToSavedPhotosAlbum之前保留組合圖像。組合的圖像是自動釋放的,並且可以在實際保存完成之前釋放它。試試這個:

//save actual design in photo library 
- (void)savePicture{ 
    UIImage *myImage = [self combineImages]; 
    [myImage retain]; 
    UIImageWriteToSavedPhotosAlbum(myImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), self); 
} 

//feedback if picture saving was successfull 
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { 
    [image release]; 
    // ... 
} 
+0

嗨Gobra,圖像被保存到圖書館,但我沒有得到「保存的警報」,之後應用程序被凍結。 – Crazer 2010-09-10 06:48:32

+0

...和我上面發佈的錯誤保持不變。 – Crazer 2010-09-10 06:49:52

0

找到了錯誤...有一種愚蠢的錯誤。 這是該行

// message = NSLocalizedString(@"Your image was saved", @""); 

我應該還沒有評論出來。 現在一切正常。