将场景保存到相机胶卷

时间:2013-10-31 15:09:52

标签: ios iphone vuforia

我正在研究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类中有这两个方法,但我也尝试从ARParentViewController保存视图(甚至将方法移动到类中)。有没有人找到解决方案?我不太确定要保存哪个视图和/或是否没有任何棘手的部分来保存包含OpeglES的视图。谢谢你的回复。

1 个答案:

答案 0 :(得分: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);