Iphone 拍摄窗口的截图
我正在使用此方法拍摄我的应用程序的屏幕截图:Iphone 拍摄窗口的截图,iphone,objective-c,ios4,Iphone,Objective C,Ios4,我正在使用此方法拍摄我的应用程序的屏幕截图: + (NSData*)TakeScreenshot { // Create a graphics context with the target size // On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration // On iOS prior to 4, fall back t
+ (NSData*)TakeScreenshot
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen]bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[window bounds].size.width * [[window layer] anchorPoint].x,
-[window bounds].size.height * [[window layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[window layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
}
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 100);
UIGraphicsEndImageContext();
return imageData;
}
问题是,我看不到状态栏。我只得到一个没有状态栏的白色区域。如何使用状态栏和其他控件(如选项卡栏、导航栏等)拍摄整个屏幕的截图
提前谢谢 你使用的或多或少是苹果公司建议的截图 问题是,这种方法在屏幕上截取应用程序输出的屏幕截图,而不是整个屏幕。状态栏位于其自己的窗口中,无法在应用程序中获取 您应该创建自己的状态栏作为图像,并将其添加到项目中,或者只剪切屏幕截图中不需要的部分
然后,我建议在论坛上搜索可能与您的问题重复的内容,如以下内容:您使用的内容或多或少是苹果公司建议的截图 问题是,这种方法在屏幕上截取应用程序输出的屏幕截图,而不是整个屏幕。状态栏位于其自己的窗口中,无法在应用程序中获取 您应该创建自己的状态栏作为图像,并将其添加到项目中,或者只剪切屏幕截图中不需要的部分
然后,我建议在论坛中搜索可能重复的问题,如以下问题:没有公共方法允许您拍摄整个屏幕的截图(即使用状态栏)。有一个虽然
UIGetScreenImage
允许您使用它来实现此功能。但是,由于它是一种私有方法,如果您将应用提交到应用商店,您的应用将被拒绝 没有公共方法允许您拍摄整个屏幕的屏幕截图(即使用状态栏)。有一个虽然UIGetScreenImage
允许您使用它来实现此功能。但是,由于它是一种私有方法,如果您将应用提交到应用商店,您的应用将被拒绝 这将导致你被应用商店拒绝。有没有办法在不被拒绝的情况下捕获整个屏幕?是否有捕获所有窗口的代码?这将导致你被应用商店拒绝。是否有任何方法可以捕获整个屏幕而不被拒绝?是否有捕获所有窗口的代码?恐怕没有解决您的问题的方法:(恐怕没有解决您的问题的方法:(可能重复的可能重复的)