For anybody who is looking for the correct answer:
NSMutableArray* windows = [[[UIApplication sharedApplication] windows] mutableCopy];
NSString *statusBarString = [NSString stringWithFormat:@"_statusBarWindow"];
UIWindow* statusBarWindow = [[UIApplication sharedApplication] valueForKey:statusBarString];
/*CGRect statusBarFrame = statusBarWindow.frame;
statusBarFrame.origin.x -= 20;
statusBarFrame.origin.y -= 20;
[statusBarWindow setFrame:statusBarFrame];*/
//statusBarWindow.backgroundColor = [UIColor blackColor];
[windows addObject:statusBarWindow];
[statusBarWindow release];
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIWindow *window in windows) {
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);
if (orientation == UIInterfaceOrientationLandscapeLeft) {
CGContextRotateCTM(context, M_PI_2);
if(![window isKindOfClass:[UIStatusBarWindow class]])
{
CGContextTranslateCTM(context, 20, -imageSize.width+20);
}
else
{
CGContextTranslateCTM(context, 0, -imageSize.width);
}
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
CGContextRotateCTM(context, -M_PI_2);
if(![window isKindOfClass:[UIStatusBarWindow class]])
{
CGContextTranslateCTM(context, -imageSize.height+20, 20);
}
else
{
CGContextTranslateCTM(context, -imageSize.height, 0);
}
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
CGContextRotateCTM(context, M_PI);
if(![window isKindOfClass:[UIStatusBarWindow class]])
{
CGContextTranslateCTM(context, -imageSize.width+20, -imageSize.height+20);
}
else
{
CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
}
}
if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
} else {
[window.layer renderInContext:context];
}
CGContextRestoreGState(context);
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
The answer is taken from here - with the solution above you are allowed to capture the statusbar as well.
PS: check the code for the right orientation and size of the screenshot ...