3

I tried below steps to capture screenshot but got black backround for MPMoviePlayerController

-(UIImage*)screenshot
{
 CGSize imageSize = [[UIScreen mainScreen] bounds].size;

CGFloat imageScale = imageSize.width / FRAME_WIDTH;

if (NULL != UIGraphicsBeginImageContextWithOptions)
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, imageScale);
else
    UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();

for (UIWindow *window in [[UIApplication sharedApplication] windows]) 
{
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
    {
        CGContextSaveGState(context);

        CGContextTranslateCTM(context, [window center].x, [window center].y);

        CGContextConcatCTM(context, [window transform]);

        CGContextTranslateCTM(context,
                              -[window bounds].size.width * [[window layer] anchorPoint].x,
                              -[window bounds].size.height * [[window layer] anchorPoint].y);

        [[window layer] renderInContext:context];

        CGContextRestoreGState(context);
    }
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;
}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
Rahul Gupta
  • 808
  • 11
  • 15

1 Answers1

2

get image from MPMoviePlayerController like this on action of button:

-(void)getScreenShotOfMPMoviePlayerController:(MPMoviePlayerController *)mpPlayer
{
   UIImage *thumbnail = [mpPlayer thumbnailImageAtTime:yourMoviePlayerObject.currentPlaybackTime 
                       timeOption:MPMovieTimeOptionNearestKeyFrame];
}

EDIT : Merge both images as one image taken from MPMoviePlayerController with the ScreenShot taken from UIWindow.

Refer ios-merging-two-images-of-different-size link for merging.

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • But, it will give only thumbnail of MPMoviePlayerController. I have other elements also on the screen with MPMoviePlayerController, and I want to capture all of them at a time. – Rahul Gupta Dec 13 '12 at 08:56
  • this method is deprecated now, what to use instead? – Stas Apr 07 '15 at 13:02
  • @Stas I believe the correct method to use now is `requestThumbnailImagesAtTimes`. – Gordonium Sep 16 '15 at 16:35