2012-03-11 19 views
5

Actualmente estoy trabajando con una aplicación de dibujo basado en GLpaint. Guardar la pantalla actual se convierte en un dolor agitado para mí. Tengo un ViewController, en la parte superior del controlador de vista he cargado mi UIIMageView y UIView (PaintingView). Ahora parece que estoy dibujando en la parte superior de UIImageView.GLPaint función Guardar (Save pantalla actual imagen de fondo)

He logrado obtener mi dibujo actual con esta pregunta GLPaint save image. Cuando intento capturar mi dibujo actual obtengo mi dibujo pero con una pantalla negra. Lo que deseo es mi dibujo con la imagen de fondo (UIImageView). ¿Debería superponer el UIView con UIImageView?

Respuesta

2

Debe cargar su imagen usando OpenGL, no UIKit (como UIImageView). De lo contrario, solo podrá capturar OpenGLView como una imagen individual, así como la vista de UIKit como una imagen diferente.

Para hacer esto, debe renderizar su imagen en una Textura en la clase PaintingView provista en el ejemplo de pintura de GL y luego cargarla dibujando un cuadrángulo sobre su vista de dibujo.

0

que utiliza este código para agarrar mi imagen de OpenGL:

-(BOOL)iPhoneRetina{ 
    return ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))?YES:NO; 
} 

void releasePixels(void *info, const void *data, size_t size) { 
    free((void*)data); 
} 

-(UIImage *) glToUIImage{ 

    int imageWidth, imageHeight; 

    int scale = [self iPhoneRetina]?2:1; 

    imageWidth = self.frame.size.width*scale; 
    imageHeight = self.frame.size.height*scale; 

    NSInteger myDataLength = imageWidth * imageHeight * 4; 

    // allocate array and read pixels into it. 
    GLubyte *buffer = (GLubyte *) malloc(myDataLength); 
    glReadPixels(0, 0, imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); 

    // make data provider with data. 
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, myDataLength, releasePixels); 

    // prep the ingredients 
    int bitsPerComponent = 8; 
    int bitsPerPixel = 32; 
    int bytesPerRow = 4 * imageWidth; 
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 
    CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast; 
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 

    // make the cgimage 

    CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); 

    UIImage *myImage = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationDownMirrored]; //Render image flipped, since OpenGL's data is mirrored 

    CGImageRelease(imageRef); 
    CGColorSpaceRelease(colorSpaceRef); 

    CGDataProviderRelease(provider); 

    return myImage; 
} 

Y éste fusionarla una imagen de fondo con:

-(UIImage*)mergeImage:(UIImage*)image1 withImage:(UIImage*)image2{ 

    CGSize size = image1.size; 

    UIGraphicsBeginImageContextWithOptions(size, NO, 0); 

    [image1 drawAtPoint:CGPointMake(0.0f, 0.0f)]; 
    [image2 drawAtPoint:CGPointMake(0.0f, 0.0f)]; 

    UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return result; 
} 

Algo como esto:

FinalImage = [self mergeImage: BackgroundImage withImage [self glToUIImage]];

Cuestiones relacionadas