Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 如何以编程方式为iphone5截图?_Xcode_Ios6_Screenshot_Capture - Fatal编程技术网

Xcode 如何以编程方式为iphone5截图?

Xcode 如何以编程方式为iphone5截图?,xcode,ios6,screenshot,capture,Xcode,Ios6,Screenshot,Capture,我希望在我的应用程序中有一个图像“保存”按钮。问题是,iPhone5和iPhone4的图像模糊。这是我现在使用的代码 对于iPhone 4和4s用户,其: if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { CGSize result = [[UIScreen mainScreen] bounds].size; if(result.height == 480) { CGRect scre

我希望在我的应用程序中有一个图像“保存”按钮。问题是,iPhone5和iPhone4的图像模糊。这是我现在使用的代码

对于iPhone 4和4s用户,其:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        UIGraphicsBeginImageContext(screenRect.size);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [[UIColor blackColor] set];
        CGContextFillRect(ctx, screenRect);
        [self.view.layer renderInContext:ctx];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


        CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 20, self.view.bounds.size.width, (self.view.bounds.size.height - 40)));

        //save photo to photoAlbum
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Saved!"
                                                          message:@"Image has been Saved, don't forget to Share!"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
        [message show];

        UIImage *image = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);

        // Request to save the image to camera roll
        UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);        }
对于iPhone 5用户,我有:

     if(result.height == 568)
    {
        CGRect screenRect = [[UIScreen mainScreen] bounds];

        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
            UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, [UIScreen mainScreen].scale);
        else
            UIGraphicsBeginImageContext(screenRect.size);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [[UIColor blackColor] set];
        CGContextFillRect(ctx, screenRect);
        [self.view.layer renderInContext:ctx];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 40, self.view.bounds.size.width, (self.view.bounds.size.height - 150)));

        //save photo to photoAlbum
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Saved!"
                                                          message:@"Image has been Saved, don't forget to Share!"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
        [message show];

        UIImage *image = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
        // Request to save the image to camera roll
        UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);        }
}

也许您可以尝试使用
CGContextSetShouldAntialias()

设置/取消设置反序列化上下文选项您可能正在捕获一个非视网膜320x480屏幕截图。请注意,
UIScreen
边界是以点来测量的,而不是像素