Java Code Examples for android.media.ExifInterface#ORIENTATION_ROTATE_90

The following examples show how to use android.media.ExifInterface#ORIENTATION_ROTATE_90 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From ObservableScheduler with Apache License 2.0 6 votes vote down vote up
private static int readPictureDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example 2
Source File: MyBitmapUtils.java    From FaceDetect with Apache License 2.0 6 votes vote down vote up
/**
 * 根据path
 * @param path
 * @return
 */
public final static int getDegress(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example 3
Source File: CropUtil.java    From ImagePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片旋转角度
 *
 * @param path 图片路径
 * @return 旋转角度
 */
public static int getExifRotation(String path)
{
    if (TextUtils.isEmpty(path))
        return 0;

    try
    {
        ExifInterface exif = new ExifInterface(path);
        // We only recognize a subset of orientation tag values
        switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED))
        {
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            default:
                return ExifInterface.ORIENTATION_UNDEFINED;
        }
    } catch (IOException e)
    {
        return 0;
    }
}
 
Example 4
Source File: ImageUtil.java    From imsdk-android with MIT License 6 votes vote down vote up
public static int getOrientation(String imagePath) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(imagePath);
        int orientation =
            exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                return 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                return 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                return 270;
            default:
                return 0;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
Example 5
Source File: Engine.java    From LLApp with Apache License 2.0 6 votes vote down vote up
private Bitmap rotatingImage(Bitmap bitmap) {
  if (srcExif == null) return bitmap;

  Matrix matrix = new Matrix();
  int angle = 0;
  int orientation = srcExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
      angle = 90;
      break;
    case ExifInterface.ORIENTATION_ROTATE_180:
      angle = 180;
      break;
    case ExifInterface.ORIENTATION_ROTATE_270:
      angle = 270;
      break;
  }

  matrix.postRotate(angle);

  return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
 
Example 6
Source File: ImageUtil.java    From QrScan with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片拍摄时的旋转角度
 *
 * @param path
 * @return
 */public static int getPictureRotateDegree(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;

}
 
Example 7
Source File: BitmapUtil.java    From lunzi with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片文件旋转的角度
 *
 * @param path 图片绝对路径
 * @return 图片旋转的角度
 */
public static int getPicRotate(String path) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(path);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL
        );
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example 8
Source File: BitmapUtil.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
public static int getBitmapDegree(String path) {
    int degree = 0;
    int orientation;
    try {
        orientation = new ExifInterface(path).getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
    } catch (IOException e) {
        Log.e(TAG, "getBitmapDegree: ", e);
        orientation = 0;
    }
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        degree = 90;
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        degree = 180;
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        degree = 270;
    }
    return degree;
}
 
Example 9
Source File: MediaStoreServiceImpl.java    From AndroidMvc with Apache License 2.0 6 votes vote down vote up
private ImageDTO.Orientation translateOrientation(int orientation) {
    switch (orientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            return ImageDTO.Orientation.FLIP_HORIZONTAL;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            return ImageDTO.Orientation.FLIP_VERTICAL;
        case ExifInterface.ORIENTATION_NORMAL:
            return ImageDTO.Orientation.NORMAL;
        case ExifInterface.ORIENTATION_ROTATE_90:
            return ImageDTO.Orientation.ROTATE_90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return ImageDTO.Orientation.ROTATE_180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return ImageDTO.Orientation.ROTATE_270;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            return ImageDTO.Orientation.TRANSPOSE;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            return ImageDTO.Orientation.TRANSVERSE;
        default:
            return ImageDTO.Orientation.UNDEFINED;
    }
}
 
Example 10
Source File: ImageUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片旋转角度
 *
 * @param filePath 文件路径
 * @return 旋转角度
 */
public static int getRotateDegree(String filePath) {
    int degree = 0;
    try {
        ExifInterface exifInterface = new ExifInterface(filePath);
        int orientation = exifInterface.getAttributeInt(
                ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            default:
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example 11
Source File: ExifHelper.java    From wildfly-samples with MIT License 5 votes vote down vote up
public int getOrientation() {
    int o = Integer.parseInt(this.orientation);

    if (o == ExifInterface.ORIENTATION_NORMAL) {
        return 0;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_90) {
        return 90;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_180) {
        return 180;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_270) {
        return 270;
    } else {
        return 0;
    }
}
 
Example 12
Source File: ExifHelper.java    From bluemix-parking-meter with MIT License 5 votes vote down vote up
public int getOrientation() {
    int o = Integer.parseInt(this.orientation);

    if (o == ExifInterface.ORIENTATION_NORMAL) {
        return 0;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_90) {
        return 90;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_180) {
        return 180;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_270) {
        return 270;
    } else {
        return 0;
    }
}
 
Example 13
Source File: BaseImageDecoder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
	int rotation = 0;
	boolean flip = false;
	try {
		ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
		int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
		switch (exifOrientation) {
			case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
				flip = true;
			case ExifInterface.ORIENTATION_NORMAL:
				rotation = 0;
				break;
			case ExifInterface.ORIENTATION_TRANSVERSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_90:
				rotation = 90;
				break;
			case ExifInterface.ORIENTATION_FLIP_VERTICAL:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_180:
				rotation = 180;
				break;
			case ExifInterface.ORIENTATION_TRANSPOSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_270:
				rotation = 270;
				break;
		}
	} catch (IOException e) {
		L.w("Can't read EXIF tags from file [%s]", imageUri);
	}
	return new ExifInfo(rotation, flip);
}
 
Example 14
Source File: BmpUtils.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 读取图片文件旋转的角度
 *
 * @param path 图片绝对路径
 * @return 图片旋转的角度
 */
public static int getPicRotate(String path)
{
    int degree = 0;
    try
    {
        if (StringUtil.isEmpty(path))
        {
            return -1;
        }
        ExifInterface exifInterface = new ExifInterface(path);

        int orientation =
                exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch (orientation)
        {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e)
    {
        KLog.e("BmpUtils.getPicRotate():filePath = " + path + "\n获取图片旋转角度失败:" + e.toString());
    }
    return degree;
}
 
Example 15
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the orientation as stored in EXIF metadata into degrees.
 *
 * @param exifOrientation The orientation as stored in the exif data.
 * @return the rotation in degrees.
 */
private static int convertExifOrientationToRotation(final int exifOrientation) {
	switch (exifOrientation) {
	case ExifInterface.ORIENTATION_ROTATE_270:
		return ROTATION_270;
	case ExifInterface.ORIENTATION_ROTATE_180:
		return ROTATION_180;
	case ExifInterface.ORIENTATION_ROTATE_90:
		return ROTATION_90;
	default:
		return 0;
	}
}
 
Example 16
Source File: ExifInterfaceCompat.java    From Matisse with Apache License 2.0 5 votes vote down vote up
/**
 * Read exif info and get orientation value of the photo.
 *
 * @param filepath to get exif.
 * @return exif orientation value
 */
public static int getExifOrientation(String filepath) {
    ExifInterface exif;
    try {
        // ExifInterface does not check whether file path is null or not,
        // so passing null file path argument to its constructor causing SIGSEGV.
        // We should avoid such a situation by checking file path string.
        exif = newInstance(filepath);
    } catch (IOException ex) {
        Log.e(TAG, "cannot read exif", ex);
        return EXIF_DEGREE_FALLBACK_VALUE;
    }

    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, EXIF_DEGREE_FALLBACK_VALUE);
    if (orientation == EXIF_DEGREE_FALLBACK_VALUE) {
        return 0;
    }
    // We only recognize a subset of orientation tag values.
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            return 90;
        case ExifInterface.ORIENTATION_ROTATE_180:
            return 180;
        case ExifInterface.ORIENTATION_ROTATE_270:
            return 270;
        default:
            return 0;
    }
}
 
Example 17
Source File: ExifHelper.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
public int getOrientation() {
    int o = Integer.parseInt(this.orientation);

    if (o == ExifInterface.ORIENTATION_NORMAL) {
        return 0;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_90) {
        return 90;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_180) {
        return 180;
    } else if (o == ExifInterface.ORIENTATION_ROTATE_270) {
        return 270;
    } else {
        return 0;
    }
}
 
Example 18
Source File: BaseImageDecoder.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri) {
	int rotation = 0;
	boolean flip = false;
	try {
		ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri));
		int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
		switch (exifOrientation) {
			case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
				flip = true;
			case ExifInterface.ORIENTATION_NORMAL:
				rotation = 0;
				break;
			case ExifInterface.ORIENTATION_TRANSVERSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_90:
				rotation = 90;
				break;
			case ExifInterface.ORIENTATION_FLIP_VERTICAL:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_180:
				rotation = 180;
				break;
			case ExifInterface.ORIENTATION_TRANSPOSE:
				flip = true;
			case ExifInterface.ORIENTATION_ROTATE_270:
				rotation = 270;
				break;
		}
	} catch (IOException e) {
		L.w("Can't read EXIF tags from file [%s]", imageUri);
	}
	return new ExifInfo(rotation, flip);
}
 
Example 19
Source File: ImageUtils.java    From android-utils with MIT License 4 votes vote down vote up
/**
 * Rotate the image at the specified uri. For the rotation of the image the
 * {@link android.media.ExifInterface} data in the image will be used.
 *
 * @param uri Uri of the image to be rotated.
 **/
public static Uri rotateImage(Context context, Uri uri) throws FileNotFoundException, IOException {
    // rotate the image
    if (uri == null) {
        throw new NullPointerException(ERROR_URI_NULL);
    }

    if (!MediaUtils.isMediaContentUri(uri)) {
        return null;
    }

    int invalidOrientation = -1;
    byte[] data = Utils.getMediaData(context, uri);

    int orientation = getOrientation(context, uri);

    Uri newUri = null;

    try {

        Log.d(TAG, "#rotateImage Exif orientation: " + orientation);

        if (orientation != invalidOrientation) {
            Matrix matrix = new Matrix();

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    matrix.postRotate(90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    matrix.postRotate(180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    matrix.postRotate(270);
                    break;
            }

            // set some options so the memory is manager properly
            BitmapFactory.Options options = new BitmapFactory.Options();
            // options.inPreferredConfig = Bitmap.Config.RGB_565; // try to enable this if
            // OutOfMem issue still persists
            options.inPurgeable = true;
            options.inInputShareable = true;

            Bitmap original = BitmapFactory.decodeByteArray(data, 0, data.length, options);
            Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true); // rotating
            // bitmap
            String newUrl = Media.insertImage(((Activity) context).getContentResolver(), rotatedBitmap, "", "");

            if (newUrl != null) {
                newUri = Uri.parse(newUrl);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return newUri;
}
 
Example 20
Source File: BitmapUtils.java    From RecyclerViewAdapter with Apache License 2.0 2 votes vote down vote up
/**

     * 读取图片的旋转的角度

     *

     * @param path

     *            图片绝对路径

     * @return 图片的旋转角度

     */

    public static int getBitmapDegree(String path) {

        int degree = 0;

        try {

            // 从指定路径下读取图片,并获取其EXIF信息

            ExifInterface exifInterface = new ExifInterface(path);

            // 获取图片的旋转信息

            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,

                    ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {

                case ExifInterface.ORIENTATION_ROTATE_90:

                    degree = 90;

                    break;

                case ExifInterface.ORIENTATION_ROTATE_180:

                    degree = 180;

                    break;

                case ExifInterface.ORIENTATION_ROTATE_270:

                    degree = 270;

                    break;

            }

        } catch (IOException e) {

            e.printStackTrace();

        }

        return degree;

    }