1

这是模拟器的屏幕截图和保存的图像:

在此处输入图像描述

代码 :

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//guru - just for simulator
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];

[UIImagePNGRepresentation(screenshotImage) writeToFile:filePath atomically:YES];
//end guru

UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);

我该如何解决这个问题?当我使用 Xcode4_iOS6 构建它时效果很好,但不适用于 Xcode5_iOS7。

4

1 回答 1

2

您可以通过以下方式修复它:

    if([self IS_IOS_7])
    {
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, TRUE, [[UIScreen mainScreen] scale]);
    }
    else
    {
        UIGraphicsBeginImageContext(self.view.bounds.size);
    }


    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);

iOS7 检查:

-(bool)IS_IOS_7
{
    NSString *currOsVersion = [[UIDevice currentDevice] systemVersion];

    float sysver = [currOsVersion floatValue] ;

    if(sysver >=7.0f)
        return true;

    return false;
}
于 2013-10-07T17:58:46.523 回答