Log in or register to post comments

Landscape screenshot returns portrait mode screen

June 16, 2014 - 10:02pm #1

I'm taking openGL screenshot , if camera at portrait mode then take the snapshot it returns portrait mode. But if i rotate the camera into landscape mode from portrait mode then take screenshot it returns portrait mode screenshot only. But my camera view is showing live stream full mode and screenshot saving 1024X768. Please see the attached image. 

ImageTargetsEAGLView.mm:

- (BOOL)presentFramebuffer

{

  if (_takePhotoFlag1)

{

   [self glToUIImage1];

     UIImageWriteToSavedPhotosAlbum([self glToUIImage1], nil, nil, nil);

      NSLog(@"Screenshot size: %d, %d", (int)[[self glToUIImage1] size].width, (int)[[self glToUIImage1] size].height);

 _takePhotoFlag1 = NO;

   }     

        // setFramebuffer must have been called before presentFramebuffer, therefore

    // we know the context is valid and has been set for this (render) thread

    

    // Bind the colour render buffer and present it

    glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);

    

    return [context presentRenderbuffer:GL_RENDERBUFFER];

}

 

 

- (UIImage*) glToUIImage1

UIImage *outputImage = nil;

        

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

        if (UIInterfaceOrientationIsLandscape(orientation))

        {

            NSLog(@"landscape screen");

            CGRect screenBounds = [[UIScreen mainScreen] bounds];

   //  CGFloat scale = [[UIScreen mainScreen] scale];

            // CGRect s = CGRectMake(0, 0, 320.0f * scale, 480.0f * scale);

              CGRect  s = CGRectMake(0, 0, 1024 , 768);

             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 context1 = 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(context1, transform);

            CGContextDrawImage(context1, CGRectMake(0.0f, 0.0f, width, height), iref);

            CGImageRef outputRef = CGBitmapContextCreateImage(context1);

               outputImage = [UIImage imageWithCGImage: outputRef];

          CGDataProviderRelease(ref);

            CGImageRelease(iref);

            CGContextRelease(context1);

            CGImageRelease(outputRef);

            free(pixels);

            free(buffer);

            

        }else{

            

         NSLog(@"portrait screen");

            

        //    CGFloat scale = [[UIScreen mainScreen] scale];

            // CGRect s = CGRectMake(0, 0, 320.0f * scale, 480.0f * scale);

            

            CGRect  s = CGRectMake(0, 0, 768, 1024);

            

            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 context1 = 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(context1, transform);

            CGContextDrawImage(context1, CGRectMake(0.0f, 0.0f, width, height), iref);

            CGImageRef outputRef = CGBitmapContextCreateImage(context1);

            

            

            outputImage = [UIImage imageWithCGImage: outputRef];

            

            CGDataProviderRelease(ref);

            CGImageRelease(iref);

            CGContextRelease(context1);

            CGImageRelease(outputRef);

            free(pixels);

            free(buffer);

            

            

        }

 

        

        return outputImage;

        

    }

    

}

 

AttachmentSize
Image icon landscape_Screen.JPG121.43 KB
Log in or register to post comments