una pantalla hacer cómo como captura boton iphone opengl-es eaglview

cómo - como hacer captura de pantalla iphone sin boton



¿Cómo puedo tomar una imagen de mi EAGLLayer? (3)

Estoy buscando la forma de tomar el contenido de mi OpenGL (como UIImage) y luego guardarlo en un archivo. Ahora estoy probando glReadPixels aunque no estoy seguro de estar haciendo lo correcto sobre qué tipo de malloc debería estar haciendo. Entiendo que en OSX es GL_BGRA pero en el iPhone eso no funciona ...


Consulte "Preguntas y respuestas técnicas QA1704 OpenGL ES View Snapshot", donde Apple ofrece un ejemplo elaborado, incluida la "mejor forma" de Nils para desplegar la imagen. Te lleva a tu UIImage, y desde allí sigue a Nils para guardarlo como un archivo.


Todas las implementaciones GL de cumplimiento de OpenGL | ES deben admitir GL_RGBA como parámetro para glReadPixels.

Si su OpenGL | Es es compatible con

GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES

extensión también puede consultar el formato nativo. glReadPixels entenderá este formato como un parámetro para glReadPixels y le permite obtener directamente los datos de píxeles en formato nativo. Esto es generalmente un poco más rápido que GL_RGBA.

Eche un vistazo al archivo de encabezado o consulte la extensión-soporte a través de glGetString.


Obtenga los datos de la vista de OpenGL ES:

-(UIImage *) snapshot { NSInteger myDataLength = backingWidth * backingHeight * 4; // allocate array and read pixels into it. GLubyte *buffer = (GLubyte *) malloc(myDataLength); glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); // gl renders "upside down" so swap top to bottom into new array. // there''s gotta be a better way, but this works. GLubyte *buffer2 = (GLubyte *) malloc(myDataLength); for(int y = 0; y <backingHeight; y++) { for(int x = 0; x <backingWidth * 4; x++) { buffer2[((backingHeight - 1) - y) * backingWidth * 4 + x] = buffer[y * 4 * backingWidth + x]; } } free(buffer); // make data provider with data. CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL); // prep the ingredients int bitsPerComponent = 8; int bitsPerPixel = 32; int bytesPerRow = 4 * backingWidth; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; // make the cgimage CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); // then make the uiimage from that UIImage *myImage = [UIImage imageWithCGImage:imageRef]; return myImage; }

Luego para guardar la imagen:

-(void) saveImage:(UIImage *)image {} // Create paths to output images NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"]; NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"]; // Write a UIImage to JPEG with minimum compression (best quality) // The value ''image'' must be a UIImage object // The value ''1.0'' represents image compression quality as value from 0.0 to 1.0 [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES]; // Write image to PNG [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES]; }