【问题标题】:Save scene to camera roll将场景保存到相机胶卷
【发布时间】:2013-10-31 15:09:52
【问题描述】:

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

【问题讨论】:

    标签: ios iphone vuforia


    【解决方案1】:

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

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

    【讨论】:

    • 做和以前一样的事情。它在图像目标中对您有用吗?对我来说很神秘:-O
    • @dew 这对我有用.. 看看你的代码就知道第一行与我的不同..
    • 您从哪个类保存视图?我尝试了我认为正确的 ImageTargetsParentViewController,但它仍然只保存图标:/
    • 你在课堂上导入了哪些框架?我导入
    • 所以我设法让它工作,但它比我预期的要难。在 vuforia web (developer.vuforia.com/forum/ios/…) 上找到了这几个解决方案,所以我将其中的几个结合起来并且它以某种方式工作。感谢回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 2016-05-01
    • 2022-01-01
    • 2015-01-06
    • 2021-03-10
    相关资源
    最近更新 更多