Création d'une capture d'écran rétine par programmation résultant en une image non rétine

J'essaie de prendre une capture d'écran de la rétine par programme et j'ai essayé toutes les approches trouvées en ligne, mais je n'ai pas réussi à get la capture d'écran de la rétine.

Je comprends l'API privée suivante:

UIGetScreenImage(); 

ne peut pas être utilisé car Apple rejettera votre application. Cependant, cette méthode returnne exactement ce dont j'ai besoin (640×960 capture d'écran de l'écran).

J'ai essayé cette méthode sur mon iPhone 4 ainsi que le simulateur de l'iPhone 4 sur le matériel de la rétine, mais l'image obtenue est toujours de 320×480.

 -(UIImage *)captureView { AppDelegate *appdelegate = [[UIApplication sharedApplication]delegate]; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) UIGraphicsBeginImageContextWithOptions(appdelegate.window.bounds.size, NO, 0.0); else UIGraphicsBeginImageContext(appdelegate.window.bounds.size); [appdelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSLog(@"SIZE: %@", NSSsortingngFromCGSize(image.size)); NSLog(@"scale: %f", [UIScreen mainScreen].scale); return image; } 

J'ai aussi essayé la méthode recommandée par Apple:

 - (UIImage*)screenshot { // 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); } } // Resortingeve the screenshot image UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSLog(@"Size: %@", NSSsortingngFromCGSize(image.size)); return image; } 

Mais il renvoie également une image non rétine: 2012-12-23 19: 57: 45.205 PostCard [3351: 707] size: {320, 480}

Y a-t-il quelque chose d'évident qui me manque? Comment se fait-il qu'il existe des methods qui sont censées prendre une capture d'écran de la rétine et me ramener des captures d'écran non retina? Merci d'avance!

Je ne vois rien de mal dans votre code. En dehors de image.size , avez-vous essayé de vous connecter à image.scale ? Est-ce 1 ou 2? Si c'est 2, c'est en fait une image de la rétine.

UIImage.scale représente l'échelle de l'image. Donc, une image avec UIImage.size étant 320 × 480 et UIImage.scale étant 2 a une taille réelle de 640 × 960. Du document d'Apple:

Si vous multipliez la taille logique de l'image (stockée dans la propriété size ) par la valeur de cette propriété, vous obtenez les dimensions de l'image en pixels.

C'est la même idée que lorsque vous chargez une image dans un UIImage avec le modificateur @2x . Par exemple:

 a.png (100×80) => size=100×80 scale=1 [email protected] (200×160) => size=100×80 scale=2