Log in or register to post comments

Take screenshot

February 2, 2012 - 3:19am #1

Hi,
is possible to take a screenshot of the screen device with AR content and save it to device album?

Tankyou

Take screenshot

May 7, 2013 - 3:27am #10

Hi Nalin,

I posted my quary many time, but you never give solution once a time. If you can give me solution then give me advice.

 

 

Khushi

Take screenshot

May 7, 2013 - 3:02am #9

Please can you avoid double posting your question, because it causes confusion and delays.

Secondly in future can you please create a new thread rather than taking over an existing thread.

I will deal with your question here:

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

 

N

Take screenshot

May 6, 2013 - 11:45pm #8

Hi,

Please give me solution?

 

 

khushi

Take screenshot

May 6, 2013 - 2:56am #7

 

Hi,

 

I got a half black screen on my album, When i take screenShot.

 

I written  following code below :-

 

@interface VBOverlayViewController : OverlayViewController {

 

 

 UIButton *takePhoto;

}

 

@property (nonatomic,assign)UIButton *takePhoto;

//For Take a screen Shot

-(UIImage *)glToUIImage;

-(void)TakePhoto;

 

 

 

 

@implementation VBOverlayViewController

@synthesize takePhoto;

 

-(void)loadView

{

 

 

   takePhoto = [[UIButton alloc]initWithFrame:CGRectMake(0147070)];

//    takePhoto.backgroundColor = [UIColor colorWithPatternImage:[]];

    [takePhoto setTitle:@"Take Photo" forState:UIControlStateNormal];

    [takePhoto.titleLabel setFont:[UIFont systemFontOfSize:12.0]];

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

    [self.view addSubview:takePhoto];

 

}

 

 

-(UIImage *)glToUIImage

{

    NSInteger myDataLength = 320 * 480 * 8;//4

    

    //allocate array and read pixels into it.

    GLubyte *buffer = (GLubyte *)malloc(myDataLength);

    glReadPixels(00320480GL_RGBAGL_UNSIGNED_BYTE, buffer);

    

    //gl renders "upside down" so swap top bottom into new array.

    //there's gotta be a better way, but this works.

    

    GLubyte *buffer2 = (GLubyte *)malloc(myDataLength);

    for(int y = 0; y<480; y++)

    {

        for (int x=0; x<320; x++) {

            

            buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];//4

        }

    }

    

    //make data provider with data.

    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);

    

    //prep the ingredients

    int bitsPerComponent = 8;//8

    int bitPerPixel = 32;//64

    int bytePerRow = 4 * 320;//4

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

    

    //make the cgimage

    CGImageRef imageRef = CGImageCreate(320480, bitsPerComponent, bitPerPixel, bytePerRow, colorSpaceRef, bitmapInfo, provider, NULLNO, renderingIntent);

    

    NSLog(@"imageRef:-%@",imageRef);

    

    //then make the uiImage from that

    UIImage *myImage = [UIImage imageWithCGImage:imageRef];

    NSLog(@"myImage:-%@",myImage);

    return myImage;

        

}

 

 

 

-(void)TakePhoto

{

    UIImage *image = [self glToUIImage];

    NSLog(@"imge:-%@",image);

    

    UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"Get It!" message:@"Go to the Album." delegate:nilcancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alert show];

    

    UIImageWriteToSavedPhotosAlbum(image, selfnilnil);

    

    

}

 
//EaglView.m-------------
 

@implementation EAGLView

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    

if (self)

    {

        

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

        

        eaglLayer.opaque = TRUE;

        //        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:

        //                                        [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking,

        //                                        kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,

        //                                        nil];

        

        

        eaglLayer.drawableProperties = @{

        

    kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:YES],

        

    kEAGLDrawablePropertyColorFormatkEAGLColorFormatRGBA8,

        

        };

 

 

What I do, because I m doing all codes.Please guide me.

Thank you

Khushi

Re: Take screenshot

February 27, 2012 - 2:24am #6

Thanks for taking the time to share that Thomas. :-)

One word of caution - it's advisable to not release the image resources until the callback from UIImageWriteToSavedPhotosAlbum - I've seen crashes where image data was released before the file was saved.

Re: Take screenshot

February 27, 2012 - 1:52am #5
reddog wrote:

Tank You MoSR,
I try to make screenshot whit this method but I can't.
Were exactly I must insert the code in Xcode?

:eek:

In my case, i used the code directly in an IBAction, and called it from a button in InterfaceBuilder. It's a bit of a shabby method, since it requires that you overlay a button as UI on top of your EAGLView, but here goes:

-(IBAction)facebookPhoto:(id)sender
{
    UIImage *outputImage = nil;
    
    CGFloat scale = [[UIScreen mainScreen] scale];
    CGRect s = CGRectMake(0, 0, 320.0f * scale, 480.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);
}

This code will take a snapshot of what's currently on your EAGLView (including both camera and 3D content), and save it as a photo to your iPhone Photo Album.

Re: Take screenshot

February 7, 2012 - 9:32am #4

The code would best live in your EAGLView and be invoked by whatever action you choose to take a photo.

Re: Take screenshot

February 7, 2012 - 9:23am #3

Tank You MoSR,
I try to make screenshot whit this method but I can't.
Were exactly I must insert the code in Xcode?

:eek:

Re: Take screenshot

February 2, 2012 - 3:43am #2

If you search the forum you'll find a number of threads about this topic.

It's really an iOS issue and there's a good solution here:

Saving screenshot of OpenGL ES content to the Photo Album

Log in or register to post comments