Rotate an UIImage before upload

146 Views Asked by At

I have the following question.

I have made an app where people can upload a picture, but i want the picture to be uploaded the way the picture was made. Now when I make a picture it is uploaded 90 degreed turned. I never said that it has to turn. I tried stuff like:

int angle = 0;
switch(image.imageOrientation)
{
    case UIImageOrientationUp:
        angle = 0;
        break;
    case UIImageOrientationDown:
        angle = 180;
        break;
    case UIImageOrientationRight:
        angle = 90;
        break;
    case UIImageOrientationLeft:
        angle = -90;
        break;
}
UIImageView *iv = [[UIImageView alloc] initWithImage:image];
if (angle == 180)
{
    NSLog(@"180");
    degrees = 180;
    radians = degrees / 57.2958;
    iv.center = CGPointMake(0, 0);
    iv.transform = CGAffineTransformMakeRotation(radians);
}
else if (angle == 90)
{
    NSLog(@"90");
    degrees = 90;
    radians = degrees / 57.2958;
    iv.center = CGPointMake(0, 0);
    iv.transform = CGAffineTransformMakeRotation(radians);
}
else if (angle == -90)
{
    NSLog(@"-90");
    degrees = 270;
    radians = degrees / 57.2958;
    iv.center = CGPointMake(0, 0);
    iv.transform = CGAffineTransformMakeRotation(radians);
}
else if (angle == 0)
{
    NSLog(@"0");
    degrees = 0;
    radians = degrees / 57.2958;
    iv.center = CGPointMake(0, 0);
    iv.transform = CGAffineTransformMakeRotation(radians);
}

but that isnt working. Can someone help me with this?

TLDR; How to check how an image is rotated and rotate it the right way? Or it this something I have to do where the image is showed?

EDIT: Tried to do it in the UIImageView afterwards, but that isn't working

0

There are 0 best solutions below