Log in or register to post comments

Screenshot won't taking 3D content

April 3, 2014 - 11:29pm #1

I'm using vuforia-sdk-ios-2-0-32. I referred below  link for taking screenshot (including both camera and 3D content) . https://developer.vuforia.com/forum/ios/vuforia-sdk-how-take-screenshotshttps://developer.vuforia.com/forum/ios/take-screenshot . But my code taking only camera image and save to Album but it's not taking withoverlay content (3D content or image). My code:

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,

      };

 

 

Screenshot won't taking 3D content

April 7, 2014 - 3:05am #16

I'm using iPadMini iOS 6.1.

Screenshot won't taking 3D content

April 7, 2014 - 3:03am #15

If i use below code it automatically taking screenshot. Please help this.

 

- (BOOL)presentFramebuffer

{

     [self glToUIImage];

    

    // setFramebuffer must have been called before presentFramebuffer, therefore

    // we know the context is valid and has been set for this (render) thread

    

    // Bind the colour render buffer and present it

    glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);

    

    return [context presentRenderbuffer:GL_RENDERBUFFER];

}

Screenshot won't taking 3D content

April 7, 2014 - 2:59am #14

This is nothing to do with Vuforia - you simply need to diagnose what the problem is and fix it.

N

Screenshot won't taking 3D content

April 7, 2014 - 12:19am #13

I referred Trigger UIEvent from here https://developer.vuforia.com/resources/dev-guide/triggering-ui-events-when-target-detected and my button is able to receive touch event but overlay content is not storing only camera image storing.

Screenshot won't taking 3D content

April 6, 2014 - 10:33pm #12

Does TargetOverlayView (invisible overlay view) hiding the button touch event?

Screenshot won't taking 3D content

April 6, 2014 - 9:01pm #11

Button is displaying now. But button click event is not working. I implemented code in ImageTargetEAGLView file.

ImgaeTargetEAGLView.h :

@interface ImageTargetsEAGLView : UIView <UIGLViewProtocol> {

@private

 UIButton *photo;

 }

@property (nonatomic) BOOL takePhotoFlag;

 

ImageTargetEAGLView.mm :

- (id)initWithFrame:(CGRect)frame appSession:(SampleApplicationSession *) app

{

    self = [super initWithFrame:frame];

   if (self) {

takePhotoFlag = NO;

       [self DisplayPhotoButton];

   return self;

}

 

- (void)takePhoto

 

{

    

    takePhotoFlag = YES;

    

    

    

}

 

 

 

- (void)DisplayPhotoButton

 

{

    

    NSLog(@"button pressed");

    

    UIImage *closeButtonImage = [UIImage imageNamed:@"button.png"];

    // UIImage *closeButtonTappedImage = [UIImage imageNamed:@"button_close_pressed.png"];

    

    CGRect aRect = CGRectMake(20,20,

                              

                              closeButtonImage.size.width,

                              closeButtonImage.size.height);

    

    photo = [UIButton buttonWithType:UIButtonTypeCustom];

    photo.frame = aRect;

    

    [photo setImage:closeButtonImage forState:UIControlStateNormal];

    

    

    photo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

    

    [photo addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];

    

    [self  addSubview:photo];

    

}

- (UIImage*) glToUIImage

 

 

 

{

    

    GLint backingWidth, backingHeight;

    

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);

    

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

    

    

    

    CGRect s = CGRectMake(0, 0, backingWidth, backingHeight);

    

    

    

    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 cgcontext = 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(cgcontext, transform);

    

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

    

    CGImageRef outputRef = CGBitmapContextCreateImage(cgcontext);

    

    

    

    UIImage* outputImage = [UIImage imageWithCGImage:outputRef];

    

    UIImageWriteToSavedPhotosAlbum(outputImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    

    

    

    CGDataProviderRelease(ref);

    

    CGImageRelease(iref);

    

    CGContextRelease(cgcontext);

    

    CGImageRelease(outputRef);

    

    

    

    free(pixels);

    

    free(buffer);

    

    

    

    NSLog(@"Screenshot size: %d, %d", (int)[outputImage size].width, (int)[outputImage size].height);

    

    

    

    return outputImage;

    

}

 

- (BOOL)presentFramebuffer

{

    

    

    if (takePhotoFlag)

        

    {

        

        [self glToUIImage];

        

        takePhotoFlag = NO;

        

    }

    

}

Screenshot won't taking 3D content

April 4, 2014 - 9:34am #10

I cannot tell you that - you need to work some things out for yourself.

What I suggest is that you try what I suggested below with Image Targets a s astarting point to learn.

Then, once it works try it with the books app.

Persistence is crucial.

 

N

Screenshot won't taking 3D content

April 4, 2014 - 9:28am #9

I used same code for Books (Cloud Reco). But my button is not displaying. Does i have to change anything for books in BookEAGLView.mm file? 

Screenshot won't taking 3D content

April 4, 2014 - 8:35am #8

In order to take a screenshot in the ImageTarget Application, which lives within the Vuforia Samples application, the code below will capture a screenshot containing the video feed as well as the augmentation when a button is pressed

 

Essentially this code adds a UI Button to the main ImageTargetsEAGLView , and when this is pressed, a  _takePhotoFlag flag is set.  This flag is checked in the presentFramebuffer() method and then the glToUIImage() method is called, which saves a photo to the users album on the device.

 

The reason this requires a flag is that the gl capture must be done prior to the frame buffer being presented, otherwise if you try to call this function as per normal you may end up with a black screen.

 

In ImageTargets EAGLView.h add the following property

 

@property (nonatomic) BOOL takePhotoFlag;

 

In the InitWithFrame() method add these two lines after initialising:

 

        _takePhotoFlag = NO;

        [self DisplayPhotoButton];

 

Add the following methods that control the taking of the photo and the button functionality:

 

- (void)takePhoto

{

    _takePhotoFlag = YES;

 

}

 

- (void)DisplayPhotoButton

{

    UIButton *photoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

   

    photoButton.frame = CGRectMake(20, 20, 200, 44);

   

    [photoButton setTitle:@"Photo" forState:UIControlStateNormal];

    [photoButton addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];

   

    [self addSubview:photoButton];

}

 

Now add the code to take the screenshot:

 

- (UIImage*) glToUIImage

 

{

    GLint backingWidth, backingHeight;

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

   

    CGRect s = CGRectMake(0, 0, backingWidth, backingHeight);

   

    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 cgcontext = 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(cgcontext, transform);

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

    CGImageRef outputRef = CGBitmapContextCreateImage(cgcontext);

   

    UIImage* outputImage = [UIImage imageWithCGImage:outputRef];

    UIImageWriteToSavedPhotosAlbum(outputImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

   

    CGDataProviderRelease(ref);

    CGImageRelease(iref);

    CGContextRelease(cgcontext);

    CGImageRelease(outputRef);

   

    free(pixels);

    free(buffer);

   

    NSLog(@"Screenshot size: %d, %d", (int)[outputImage size].width, (int)[outputImage size].height);

   

    return outputImage;

}

 

// callback for UIImageWriteToSavedPhotosAlbum

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {

   

    if (error) {

        NSLog(@"Photo save error");

    }

    else {

        NSLog(@"Photo saved");

    }

}

 

Finally all that remains is to add this code to the top of presentFrameBuffer()

 

    if (_takePhotoFlag)

    {

        [self glToUIImage];

        _takePhotoFlag = NO;

    }

 

HTH

N

Screenshot won't taking 3D content

April 4, 2014 - 6:14am #7

I'm using iPadMini  iOS 6.1

Screenshot won't taking 3D content

April 4, 2014 - 5:08am #6

I downloaded vuforia 2-8-9 sample apps. And in Books app i did changes for taking screenshot. But still it's taking only camera image it won't taking camera image with augmented image content. I changes below code:

 

BooksEAGLView.mm :

- (id)initWithFrame:(CGRect)frame  delegate:(id<BooksControllerDelegateProtocol>) delegate appSession:(SampleApplicationSession *) app

{

    self = [super initWithFrame:frame];

    

    if (self) {

 CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        

        eaglLayer.opaque = TRUE;

        

        eaglLayer.drawableProperties = @{

                                         

                                         kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],

                                         

                                         kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8,

                                         

                                         };

        

}

 

BookOverlayViewController.mm:

-(void)screenshot:(id)sender{

 UIImage *outputImage = nil;

        

        CGFloat scale = [[UIScreen mainScreen] scale];

        // CGRect s = CGRectMake(0, 0, 320.0f * scale, 480.0f * 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);

        

        NSLog(@"Screenshot size: %d, %d", (int)[outputImage size].width, (int)[outputImage size].height);

        }

Screenshot won't taking 3D content

April 4, 2014 - 2:40am #5

Screenshot won't taking 3D content

April 4, 2014 - 1:37am #4

How can i use older version code to newer version? 

Screenshot won't taking 3D content

April 4, 2014 - 1:36am #3

ok thanks...then does my code is correct in putting ARParentViewController.mm file or i need to setup somewhere?

Screenshot won't taking 3D content

April 4, 2014 - 1:26am #2

I'm using vuforia-sdk-ios-2-0-32

Sorry, older versions of the SDK are not supported.

 

N

Log in or register to post comments