iOS camera direction problem, oneself for a long time is not clear, now tidy up a bit.
Three questions:
1. When the iphone is photographed, that direction is positive (uiimageorientationup)?
2. Why is the Uiimageview direction displayed correctly, but not correctly after uploading to the server?
3. How do I adjust the direction?
The first question: is the iphone the right way to take a picture?
(Positive direction) Uiimageorientationup
And the way we usually take pictures is (uiimageorientationright)
Have you been surprised?
Second question: Why is the uiimageview direction displayed correctly?
When taking a picture, the camera stores the orientation property of the phone at this time in the UIImage imageorientation.
Uiimageview is smart, and when displayed it adjusts the direction of the final display based on the Imageorientation property of the UIImage object. so no matter what direction we take when we take the picture, it all shows up normally.
But actually the uiimage image data is stored according to the angle of the physical camera. so~
The third question: How do you adjust the direction?
@interfaceUIImage (Utility)-(UIImage *) Orientationcorrectedimage;@end@implementationUIImage (Utility)-(UIImage *) orientationcorrectedimage{UIImage* Resultimage =Nil; Resultimage=Self ; Uiimageorientation imageorientation=self.imageorientation; if(Imageorientation! =uiimageorientationup) {Uigraphicsbeginimagecontext (self.size); [Self Drawinrect:cgrectmake (0,0, Self.size.width, Self.size.height)]; Resultimage=Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); } returnresultimage;}@end
Sample code (Learn more): https://github.com/github-xiaogang/CameraDemo/
iOS camera orientation