2012-11-23 65 views
0

我需要從uiimagepicker獲取圖片,並需要在uiimageview中顯示它。它在模擬器中完美工作。但是在設備上,來自uiimagepicker的圖像旋轉。如何解決此問題?來自UIIMagePicker的圖片旋轉

+0

它再旋轉到其原來的 –

回答

0

由於手機相機的縱向/橫向取向發生此問題。再旋轉圖像像

CGImageRef imageRef = [sourceImage CGImage]; 

UIImage *rotatedImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp]; 

或嘗試這樣

static inline double radians (double degrees) {return degrees * M_PI/180;} 
UIImage* rotate(UIImage* src, UIImageOrientation orientation) 
{ 
    UIGraphicsBeginImageContext(src.size); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if (orientation == UIImageOrientationRight) { 
     CGContextRotateCTM (context, radians(90)); 
    } else if (orientation == UIImageOrientationLeft) { 
     CGContextRotateCTM (context, radians(-90)); 
    } else if (orientation == UIImageOrientationDown) { 
     // NOTHING 
    } else if (orientation == UIImageOrientationUp) { 
     CGContextRotateCTM (context, radians(90)); 
    } 

    [src drawAtPoint:CGPointMake(0, 0)]; 

    return UIGraphicsGetImageFromCurrentImageContext(); 
} 
+0

Thanks.But它沒有工作 –

+0

我編輯我的答案,嘗試的東西。 – MrWaqasAhmed

+0

當然...會嘗試讓你知道...... –