截图不会拍摄3D内容

时间:2014-04-04 06:53:26

标签: ios opengl-es screenshot augmented-reality vuforia

我使用的是vuforia-sdk-ios-2-0-32。我在下面提到了获取截图的链接(包括相机和3D内容)。 https://developer.vuforia.com/forum/ios/vuforia-sdk-how-take-screenshotshttps://developer.vuforia.com/forum/ios/take-screenshot。但我的代码只拍摄相机图像并保存到相册,但它没有采用重叠内容(3D内容或图像)。

ARParentViewController.mm:

-(void)screenshot:(id)sender{

 UIImage *outputImage = nil;

        CGFloat scale = [[UIScreen mainScreen] scale];

    CGRect  s = CGRectMake(0, 0, (768.0f) * scale, 1024.0f * scale);

 uint8_t *buffer = (uint8_t *) malloc(s.size.width * s.size.height * 4);

 glReadPixels(0, 0, s.size.width, s.size.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

   CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, buffer, s.size.width * s.size.height * 4, NULL);

     CGImageRef iref = CGImageCreate(s.size.width, s.size.height, 8, 32, s.size.width * 4, CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault, ref, NULL, true, kCGRenderingIntentDefault);

   size_t width = CGImageGetWidth(iref);

    size_t height = CGImageGetHeight(iref);

    size_t length = width * height * 4;

    uint32_t *pixels = (uint32_t *)malloc(length);

   CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * 4,

    CGImageGetColorSpace(iref), kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Big);

   CGAffineTransform transform = CGAffineTransformIdentity;

        transform = CGAffineTransformMakeTranslation(0.0f, height);

        transform = CGAffineTransformScale(transform, 1.0, -1.0);

        CGContextConcatCTM(context, transform);

        CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), iref);

        CGImageRef outputRef = CGBitmapContextCreateImage(context);

   outputImage = [UIImage imageWithCGImage: outputRef];

       CGDataProviderRelease(ref);

        CGImageRelease(iref);

        CGContextRelease(context);

        CGImageRelease(outputRef);

        free(pixels);

        free(buffer);

    UIImageWriteToSavedPhotosAlbum(outputImage, nil, nil, nil);

}

AR_EAGLView.mm:

eaglLayer.drawableProperties = @{

                                    kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],

                                    kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8,

      };

0 个答案:

没有答案