0

uiimagepicker から画像を取得し、それを uiimageview に表示する必要があります。シミュレーターでは完全に動作していますが、デバイスでは、uiimagepicker からの画像が回転しています。これを解決するにはどうすればよいですか?

4

2 に答える 2

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();
}
于 2012-11-23T14:09:36.223 に答える