Hi,
I'm testing Image Targets sample project and trying to include a method to take screenshots (in iOS).
The device takes the screenshot but 9 out of 10 pictures (approx) are just black pictures.
My method is allocated in ARViewController.mm and executed via an overlay button.
Code is the following:
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);
Do you know which is the problem?
I'm using iOS6 , iPhone 3GS and iPhone 4.
Thanks in advance and sorry for my english :)
Marc
Problem with screenshots in iOS
Hi buffetlibre,
The problem could be that the code is not capturing the OpenGL ES frame buffer.
Have a look at this link on the Apple developer web site that shows how to capture screenshots and also how to extend this to OpenGL ES buffers.
Problem with screenshots in iOS
Thanks Nathan, I will investigate.
I have included this code because I saw it on:
https://ar.qualcomm.at/content/take-screenshot
But it's not working.
Thanks anyaway!
Marc