Repair of photo rotation problems caused by calling system camera

Source: Internet
Author: User

Title, it is believed that many developers, when they call the system camera to receive the photos taken, found that the photos were rotated 90 degrees without reason. The problem is reflected in most of the Samsung phones, and of course the other machines have not yet been fully tested, in short there are problems.
The following solutions are thought to be:

    1. Identify the model, get the phone model, and then determine if you need to rotate;
    2. Determine if rotation is required by obtaining the width and height of the photo;
    3. Write a camera activity yourself to get camera data, save photos;
    4. Analyze the rotated photo data, dynamically determine if rotation is required, and rotate the correct angle.

The first three methods are not ideal solutions.
First of all say 1: This is similar to the poor way, there will always be forgotten "corner", maintenance of these models would be very cumbersome;
Then say 2: If so, if just the user to horizontal screen photos, or will occur rotation;
Finally say 3: This method is I wait "lazy" programmer can do? (PS: In fact, the demand is limited, their own photo app, time-consuming + energy + easy to make a bug. The benefit is that users will feel they are always in the same app, not jump. )
So how does the fourth approach work?
First through analysis, usually a picture contains many EXIF information. This information includes the equipment to be photographed, the exposure, and whether or not the Flash is used in various contents. This includes the angle, which is the crux of the problem of rotation.
The phone's own photo viewer (some models) analyzes this information when it is displayed, and automatically rotates the photo to the appropriate angle when the information is analyzed. The more common angles are 90, 180, 270. Most Samsung phones take pictures with a 90-degree angle at the vertical screen and 0 degrees across the screen. Therefore, the solution of the idea is to follow the EXIF angle information to rotate. Mainly used in the Android API matrix. The key code can refer to the following code slice:

 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 the bitmap object, I need to show in the back here, so there is no recycle (), remind everyone to avoid memory overflow.
In this way, it is possible to solve the problem of photo rotation by using this universal method, whether it is Samsung or any other model.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Repair of photo rotation problems caused by calling system camera

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.