簡體   English   中英

將UIImage保存為PNG,重啟應用后無法加載圖像

[英]Saving a UIImage as a PNG, can't load image after restarting app

我正在使用它來將UIImage保存為PNG

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSTimeInterval timeInMiliseconds = [[NSDate date] timeIntervalSince1970];
    NSString *generatedString = [NSString stringWithFormat:@"background%f.png", timeInMiliseconds];
    NSString  *pngPath = [documentsDirectory stringByAppendingPathComponent:generatedString];
    [UIImagePNGRepresentation(customBackground) writeToFile:pngPath atomically:YES];

我將pngPath從上面保存到plist中,然后在其中使用字符串:

UIImage *image = [UIImage imageWithContentsOfFile:string];

作為字符串,該字符串顯示在右邊,我可以在圖像文件顯示的確切位置看到它。

現在奇怪的是只要我不關閉應用程序,該方法就可以正常工作,但是如果我關閉並重新打開應用程序,則UIImage文件將保持為零。 有什么想法嗎?

我是一個白痴...

保存和檢索的字符串在文檔和文件名之間缺少“ /”。 加入它,它的作品。 現在我很好奇,當應用程序永不關閉時,它是如何工作的。 感謝您的幫助。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM