Log in or register to post comments

How to take screenshot with background and Augment image

April 3, 2014 - 9:05am #1

I'm using Cloud Reco for iOS. It's working fine. When my target image is detect i'm displaying Image on top of the cameraview. For example, if i scan traget any displaying mustache image and applying this image to user face. I used pinch, drag, etc. How can i take screenshot with person face and mustache? 

How to take screenshot with background and Augment image

April 4, 2014 - 1:27am #9

Sorry, we are not here to check your code - that's up to you.

N

How to take screenshot with background and Augment image

April 3, 2014 - 10:03am #8

@Nalin: It's a previous sample only. In the thread i found your answer: You mentioned in AR_EAGLView.mm. Does my below code is correct?

How to take screenshot with background and Augment image

April 3, 2014 - 9:47am #7

If you read the thread it is in the xxxGLView.

However it was for the previous samples, so you may need to experiment a bit.

 

good luck

N

How to take screenshot with background and Augment image

April 3, 2014 - 9:44am #6

@Nalin: I saw this link. I comeup with below code. Is it correct? Where to paste this code, means which viewcontroller?

 

- (BOOL)presentFramebuffer
{
    if (takePhoto)
    {
        [self glToUIImage];
        takePhoto = NO;
    }
 
....remaining code ...
}
 
 
- (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");
    }
}
 
 
-(void)TakePhoto
{
    UIImage *image = [self glToUIImage];
   
    
    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
    
    
}

How to take screenshot with background and Augment image

April 3, 2014 - 9:30am #5

Search sometimes works better when you add more keywords e.g. "screenshot ios"

...which would eventually yield something like this...

https://developer.vuforia.com/forum/ios/vuforia-sdk-how-take-screenshots

Persistence is crucial :)

 

N

How to take screenshot with background and Augment image

April 3, 2014 - 9:27am #4

See this:

https://developer.vuforia.com/forum/faq/android-how-can-i-capture-ar-view

this tutorial is for Android, but since the capturing technique is essentially based on simple OpenGL code (glReadPikels), it should be straightforward to port to iOS.

 

How to take screenshot with background and Augment image

April 3, 2014 - 9:18am #3

I tried with keyword taking screenshot but it suggesting only Unity screenshot. Plese helpme out. 

How to take screenshot with background and Augment image

April 3, 2014 - 9:14am #2

Try searching the forums for screenshot and maybe you may find some code that could help you.

 

N

Log in or register to post comments