Acquisition and change of picture orientation in iOS development

Source: Internet
Author: User

iOS development in the use of photos more or less encountered such a problem is that I want to use the picture has a vertical row, so I chose the picture after the effect also disorder display effect is not good

Like what:

The image of the red circle selected in the picture is a sideways picture, so the avatar is displayed sideways

Problem Description:

Friends who have used an iphone or ipad do not know if they have encountered this problem, when exporting photos from the device to Windows, they often find that the direction of the exported photo is problematic, either sideways or upside down, and rotated to fit the watch. If you are browsing directly on these devices, the photos will always show the correct orientation and will be displayed correctly on your Mac. Recently in the development of iOS also encountered the same problem, the photos were uploaded to the server, then by the Windows side download the photo, found that the phone is full of normal photos to the disorder shown here. Why does the same photo behave differently on different devices? How can you avoid this situation

Workaround:

To solve this problem we need to get information about the image, to check the direction of the image to make adjustments according to the direction:

The UIImage object has a property called: Imageorientation, which stores the direction information:

It has a total of eight values:

Then we can rotate the image accordingly according to this attribute, so that the original data of the image is rotated in the correct direction, and the picture can be browsed without the direction information.

Workaround:

-(UIImage *) normalizedimage {     ifreturn self ;        Uigraphicsbeginimagecontextwithoptions (Self.size, NO, Self.scale);     [Self Drawinrect: (cgrect) {00, self.size}];      *normalizedimage = uigraphicsgetimagefromcurrentimagecontext ();     Uigraphicsendimagecontext ();      return normalizedimage;}

This is done using the Drawinrect method in UIImage, which draws the image onto the canvas and considers the orientation of the image.

Reference Details: Cocochina

Acquisition and change of picture orientation in iOS development

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.