Test soit
[UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight
[UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft
(and possibly more orientations)
faire ensuite les transformations appropriées à l'image.
Cela peut se faire de plusieurs façons, celui-ci ne prend pas beaucoup de code:
/// click action saves orientation & picture:
-(void)screenshot
{
self.orientationWhenPicked = [UIDevice currentDevice].orientation;
CGImageRef screen = UIGetScreenImage();
self.image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
}
/// somewhere else we are called for the image
-(UIImage*)getScreenshot
{
UIDeviceOrientation useOrientation = self.orientationWhenPicked;
UIImage *img = self.image;
UIGraphicsBeginImageContext(CGSizeMake(480.0f, 320.0f));
CGContextRef context = UIGraphicsGetCurrentContext();
if (useOrientation == UIDeviceOrientationLandscapeRight)
{
CGContextRotateCTM (context, M_PI/2.0f);
[img drawAtPoint:CGPointMake(0.0f, -480.0f)];
} else {
CGContextRotateCTM (context, -M_PI/2.0f);
[img drawAtPoint:CGPointMake(-320.0f, 0.0f)];
}
UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ret;
}
je l'ai modifié un peu avant de poster pour le rendre autonome, mais il devrait fonctionner avec un peu d'effort (par exemple créer self.image
etc). Vous pouvez simplement les mélanger en une seule fonction.
Notez que UIGetScreenImage() a été rendu privé par Apple encore, et votre application sera rejetée si elle utilise cette fonction: http://www.drahtwerk.biz/EN/Blog.aspx/iOS-4-updates- retardé /? newsID = 45 –