iOS - UIImageView - how to handle UIImage image orientation
If I understand, what you want to do is disregard the orientation of the UIImage? If so then you could do this:
UIImage *originalImage = [... whatever ...];
UIImage *imageToDisplay =
[UIImage imageWithCGImage:[originalImage CGImage]
scale:[originalImage scale]
orientation: UIImageOrientationUp];
So you're creating a new UIImage with the same pixel data as the original (referenced via its CGImage property) but you're specifying an orientation that doesn't rotate the data.
iOS UIImage: set image orientation without rotating the image itself
- (UIImage *)removeRotationForImage:(UIImage*)image {
if (image.imageOrientation == UIImageOrientationUp) return image;
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
[image drawInRect:(CGRect){0, 0, image.size}];
UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return normalizedImage;
}
IOS :Get UIImage Orientation inside a UIImageview with exif data?
You can use myImage.imageOrientation
, which will give you the UIImageOrientation.
OR
If you used UIImagePickerViewController
then use its delegate method
"imagePickerController:didFinishPickingMediaWithInfo:"
In This method you can also access the info dictionary
NSlog(@"%d", [info objectForKey:@"Orientation"]);
Save UIImage, Load it in Wrong Orientation
I have faced similar problem and here is how I solved it.
While we save image we need to save its orientation information along with the image ...
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setInteger:[myImage imageOrientation] forKey:@"kImageOrientation"];
[imageOrientation release];
And we load image we need to read its orientation information and apply it to the image…
UIImage *tempImage = [[UIImage alloc] initWithContentsOfFile:fullPath];
UIImage *orientedImage= [[UIImage alloc] initWithCGImage: tempImage.CGImage scale:1.0 orientation:imageOrientation];
[tempImage release];
orientedImage
is what we need.
Thanks,
Best way to manage image orientation?
I found my error!!
I was saving the image using UIImagePNGRepresentation(image);
so the image lose the orientation and when I wanted to use it, the image already was a default orientation that isn´t the correct one.
The solution is to use UIImageJPEGRepresentation(image, 1.0);
instead of UIImagePNGRepresentation(image);
and for automatically the image save with the correct orientation.
Related Topics
Changing Navigation Bar Color in Swift
How to Convert a String to an Md5 Hash in iOS Using Swift
How to Create a Circular Progress Indicator for a Count Down Timer
Using Multiple Storyboards in iOS
How to Crop Uiimage on Oval Shape or Circle Shape
Navigationlink Works Only for Once
How to Delete All Cookies of Uiwebview
How to Implement the Hashable Protocol in Swift for an Int Array (A Custom String Struct)
Dismiss Keyboard on Touch Anywhere Outside Uitextfield
Working with C APIs from Swift
Dynamically Changing Font Size of Uilabel
Rsa Implementations in Objective C
Xcodebuild Different Provisioning Profile for Target Dependency
How to Create a Delay in Swift
Using Iskindofclass with Swift
How to Get Unique Id in iOS Device