Is it possible to setup UIImageView
to handle image orientation? When I set the UIImageView
to image with orientation RIGHT (it is photo from camera roll), the image is rotated to right, but I want to show it in proper orientation, as it was taken.
I know I can rotate image data but it is possible to do it more elegant?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
Once the CSS code is applied to your . css file, stylesheet, or <style> tags, you can use the CSS class name in any of your image tags. To rotate an image by another measure of degrees, change the "180" in the CSS code and <img> tag to the degree you desire.
You can get the orientation by using image. imageOrientation .
The EXIF orientation value is used by Photoshop and other photo editing software to automatically rotate photos, saving you a manual task.
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.
You can completely avoid manually doing the transforms and scaling yourself, as suggested by an0 in this answer here:
- (UIImage *)normalizedImage { if (self.imageOrientation == UIImageOrientationUp) return self; UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale); [self drawInRect:(CGRect){0, 0, self.size}]; UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return normalizedImage; }
The documentation for the UIImage methods size and drawInRect explicitly states that they take into account orientation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With