2013-10-31 60 views
0

我正在爲iPhone增強現實應用程序工作,我正在使用來自Vuforia SDK的示例代碼「ImageTargets」。我使用我自己的圖像作爲模板和我自己的模型來增強場景(只是OpenGL中的幾個頂點)。接下來我要做的是按下按鈕後將場景保存到相機滾動。我創建了按鈕以及按鈕響應的方法。棘手的部分來了。當我按下按鈕時,該方法被調用,圖像被正確保存,但圖像是完全白色的,只顯示按鈕圖標(如http://tinypic.com/r/16c2kjq/5)。將場景保存到相機膠捲

- (void)saveImage { 
    UIGraphicsBeginImageContext(self.view.layer.frame.size); 
    [self.view.layer renderInContext: UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    UIImageWriteToSavedPhotosAlbum(viewImage, self, 
    @selector(image:didFinishSavingWithError:contextInfo:), nil); 
} 

- (void)image: (UIImage *)image didFinishSavingWithError:(NSError *)error 
    contextInfo: (void *) contextInfo { 
    NSLog(@"Image Saved"); 
} 

我在ImageTargetsParentViewController類這2種方法,但我也試圖從節約的ARParentViewController視圖(甚至是移動的方法的類)。有沒有人找到解決方案?我不確定要保存哪個視圖和/或保存包含OpeglES的視圖是否有任何棘手的部分。謝謝你的回覆。

回答

0

嘗試使用此代碼保存照片:

- (void)saveImage { 

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *imagee = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGRect rect; 
rect = CGRectMake(0, 0, 320, 480); 
CGImageRef imageRef = CGImageCreateWithImageInRect([imagee CGImage], rect); 
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 
UIImageWriteToSavedPhotosAlbum(img, Nil, Nil, Nil); 
+0

像以前一樣做同樣的事情。它在圖像目標中適合你嗎?對我來說奧祕:-O – libec

+0

@dew這個工作對我來說..看着你的代碼就知道第一行與我的不同.. – Ilario

+0

你從哪個類保存視圖?我試過ImageTargetsParentViewController,我認爲它是正確的,但它仍然只保存了圖標:/ – libec

相關問題