Call the System camera to fix photo rotation problems, camera photos

Source: Internet
Author: User

Call the System camera to fix photo rotation problems, camera photos

For example, I believe many developers have found that the photos have been rotated 90 degrees without reason when they call the System camera to receive the photos. This problem is reflected in most SamSung mobile phones. Of course, other machines have not been completely tested yet. In short, there is a problem.
As a result, we thought of the following solutions:

The first three methods are not ideal solutions.
First of all, 1. There will always be forgotten "corners" in this method similar to the effort. It will be cumbersome to maintain these models;
2: In this case, if the user just needs to take a portrait, the image will still rotate;
Finally, 3: Is this method what I can do for "lazy" programmers? (PS: in fact, the demand is limited. It takes time, effort, and bug to write a photo APP by yourself. The advantage is that the user will feel that he is always in the same APP, instead of redirecting .)
So how is the fourth solution implemented?
First, through analysis, a photo usually contains a lot of EXIF information. The information includes the device, exposure, and whether the flashlight is used. This includes the angle, that is, the crux of the rotation problem.
The photo viewer of the mobile phone itself (some models) analyzes the information when displaying the photos. when analyzing the angle information, the photos are automatically rotated to the appropriate angle. The common angles are 90, 180, and 270. Most SamSung mobile phones take a 90-degree portrait while taking a portrait, with a 0-degree landscape. Therefore, the solution is to rotate according to the angle information in EXIF. It mainly uses Matrix in Android APIs. For the key code, refer to the following code snippets:

 ExifInterface exifInterface = new ExifInterface(APPCFG.IMAGE_FILE); int orientationDegree = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Matrix matrix = new Matrix(); matrix.reset(); if (orientationDegree == ExifInterface.ORIENTATION_ROTATE_90) {    matrix.postRotate(90); } if (orientationDegree == ExifInterface.ORIENTATION_ROTATE_180) {    matrix.postRotate(180); } if (orientationDegree == ExifInterface.ORIENTATION_ROTATE_270) {    matrix.postRotate(270); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),bitmap.getHeight(), matrix, true);

In the above Code, bitmap is a Bitmap object. I need to display it later here, so there is no recycle () for the time being. Remind everyone to avoid memory overflow.
By now, no matter what Samsung or other models, this general method can be used to solve the problem of photo rotation.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.