2010-10-06 4 views
0

Mon code est ci-dessous. est-ce que quelqu'un sait ce qui se passe?Problème de rotation UIImage

Désolé pour l'information incomplète. L'image disparaît juste!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    UIImage *imCaptured = [info valueForKey:@"UIImagePickerControllerOriginalImage"]; 
    CGImageRef cgirCropped = CGImageCreateWithImageInRect(imCaptured.CGImage, CGRectMake(700.0f, 430.0f, 650.0f, 650.0f)); 
    UIImage *imCropped = [UIImage imageWithCGImage:cgirCropped]; 

    UIGraphicsBeginImageContext(imCropped.size); 
    CGContextRef cgcrRotation = UIGraphicsGetCurrentContext(); 

    switch (imCaptured.imageOrientation) { 
     case UIImageOrientationUp: 
      CGContextRotateCTM(cgcrRotation, (180 * M_PI/180)); 
      break; 
     case UIImageOrientationDown: 

      break; 
     case UIImageOrientationLeft: 

      break; 
     case UIImageOrientationRight: 
      CGContextRotateCTM(cgcrRotation, (90 * M_PI/180)); 
      break; 
    } 
    [imCropped drawAtPoint:CGPointMake(0.0f, 0.0f)]; 
    [imvPreview setImage:UIGraphicsGetImageFromCurrentImageContext()]; 
} 
+0

il aide si vous ajoutez ce qui va mal (erreur? tourne mal? ne fait rien?) – cobbal

Répondre

3

Je ne l'ai pas testé le code, mais je pense qu'il tourne autour de l'origine, vous avez donc besoin de traduire aussi bien, quelque chose comme:

... 
case UIImageOrientationUp: 
     CGContextRotateCTM(cgcrRotation, (180 * M_PI/180)); 
     CGContextTranslateCTM(ctxt, -imCropped.size.width, -imCropped.size.height); 
     break; 
...