2012-05-22 56 views
4

我采取的截图使用下面的代码:截图使用UIGraphicsBeginImageContextWithOptions为iPad 3(视网膜)

// Returns 1024x768 for iPad Retina 
    CGSize screenDimensions = [[UIScreen mainScreen] bounds].size; 

    // Create a graphics context with the target size 
    // (last parameter takes scale into account) 
    UIGraphicsBeginImageContextWithOptions(screenDimensions, NO, 0); 

    // Render the view to a new context 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    [myView.layer renderInContext:context]; 

    // Save to Camera Roll 
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
    UIImageWriteToSavedPhotosAlbum(screenshot, self, nil, nil); 

    UIGraphicsEndImageContext(); 

这工作,但我有一个用户,这将导致图像在相机胶卷的报告这不是iPad视网膜解析度。相反,它看起来更像iPad非视网膜分辨率。 (我没有iPad 3来测试它)。

还有什么我做错了吗?

回答

2

因此,我终于得到了一个物理iPad的视网膜,我原本贴的代码工作正常。生成的图像似乎处于完整的视网膜分辨率。

0

下面是我使用的代码,我似乎没有任何与iPad 3有关的问题。您也可以在iOS模拟器中使用视网膜iPad进行确认。我的代码也将文件保存到文档目录。你可以修改它,看你是否适合。

CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size; 
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef ctx = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4*(int)screenSize.width, colorSpaceRef, kCGImageAlphaPremultipliedLast); 
    CGContextTranslateCTM(ctx, 0.0, screenSize.height); 
    CGContextScaleCTM(ctx, 1.0, -1.0); 

    [(CALayer*)self.view.layer renderInContext:ctx]; 

    CGImageRef cgImage = CGBitmapContextCreateImage(ctx); 
    UIImage *image = [UIImage imageWithCGImage:cgImage]; 
    CGImageRelease(cgImage); 
    CGContextRelease(ctx); 
    CGColorSpaceRelease(colorSpaceRef); 
    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSString *filePath = [NSString stringWithFormat:@"%@/myscreenshot.jpg", docDir]; 

    [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES]; 
相关问题