繁体   English   中英

将场景保存到相机胶卷

[英]Save scene to camera roll

我正在为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的视图时是否没有棘手的部分。 感谢您的任何答复。

尝试使用此代码保存照片:

- (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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM