iOS camera orientation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.