2010-03-19 142 views
0

我試圖將UIImageView圖像保存爲PNG文件,然後使用該文件作爲GLTexture。 我遇到了麻煩,當我嘗試在模擬器中運行我的代碼時,XCode說它成功了,但模擬器崩潰而沒有錯誤消息。有人可以幫我弄這個嗎? 這裏是我的代碼:使用UIImagePNGRepresentation需要幫助

NSString *dataFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Picture.png"]; 

    NSData *imageData = UIImagePNGRepresentation(imageView.image); 
    [imageData writeToFile:dataFilePath atomically:YES]; 

    // Load image into texture 
    loadTexture("Picture.png", &Input, &renderer); 
+0

確保左上角的構建配置設置爲Debug(例如「Simulator -3.0 | Debug」),並執行** Build> Build and Debug **。然後執行** Run> Console **來查看您的控制檯。這應該會顯示你的錯誤信息。 – Tom 2010-03-19 04:06:36

+0

也檢查dataFilePath和imageData ...他們中的任何一個NULL? Path是否有有效的字符串? – 2010-03-19 04:34:34

+0

當我運行Build&Debug並查看控制檯時,我發現問題在於我的「Picture.png」文件未找到。我怎樣才能讓我的UIImageView保存到我可以在我的應用程序中使用的png文件中? – user297073 2010-03-19 05:09:29

回答

-1

試試這個:

NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:@"Picture" ofType:@"png"]; 
+0

我試過了,但是我收到了這個錯誤信息「斷言失敗:(CGImage),函數loadTexture,文件程序收到信號:」SIGABRT「。」 這是我的代碼://保存圖片 NSString * dataFilePath = [[NSBundle mainBundle] pathForResource:@「Picture」ofType:@「png」]; NSData * imageData = UIImagePNGRepresentation(imageView.image); \t \t [imageData writeToFile:dataFilePath atomically:YES]; //將圖像加載到紋理中 loadTexture(「Picture.png」,&Input,&renderer); 它崩潰的線: CGImageRef CGImage = [UIImage imageNamed:[NSString stringWithUTF8String:name]]。 rt_assert(CGImage); – user297073 2010-03-19 15:58:33

+1

iOS應用程序無法在自己的捆綁包內編寫代碼。 – 2013-05-14 23:05:20

1

您的回覆Metalmi來看,它看起來像你不給我們您正在編譯的實際代碼。如果你真的在做你看起來像是在做的事情,那麼你正試圖將數據寫入你的應用程序的捆綁包,這將失敗,因爲你不允許這樣做。您能否向我們提供您正在嘗試執行的確切代碼?