Java Code Examples for android.media.ExifInterface#ORIENTATION_ROTATE_180

The following examples show how to use android.media.ExifInterface#ORIENTATION_ROTATE_180 . 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: Camera1Manager.java    From sandriosCamera with MIT License 6 votes vote down vote up
@Override
protected int getPhotoOrientation(@CameraConfiguration.SensorPosition int sensorPosition) {
    int rotate;
    if (currentCameraId.equals(faceFrontCameraId)) {
        rotate = (360 + faceFrontCameraOrientation + configurationProvider.getDegrees()) % 360;
    } else {
        rotate = (360 + faceBackCameraOrientation - configurationProvider.getDegrees()) % 360;
    }

    if (rotate == 0) {
        orientation = ExifInterface.ORIENTATION_NORMAL;
    } else if (rotate == 90) {
        orientation = ExifInterface.ORIENTATION_ROTATE_90;
    } else if (rotate == 180) {
        orientation = ExifInterface.ORIENTATION_ROTATE_180;
    } else if (rotate == 270) {
        orientation = ExifInterface.ORIENTATION_ROTATE_270;
    }

    return orientation;
}
 
Example 2
Source File: PhotoHelper.java    From sctalk with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片属性:旋转的角度
 * 
 * @param path 图片绝对路径
 * @return degree旋转的角度
 */
public 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) {
        Logger.getLogger(PhotoHelper.class).e(e.getMessage());
    }
    return degree;
}
 
Example 3
Source File: CursorUtils.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
private static int getOrientationFromExif(String path) {
    int orientation = -1;
    try {
        ExifInterface exif = new ExifInterface(path);
        String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;

        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                orientation = 90;
            case ExifInterface.ORIENTATION_ROTATE_180:
                orientation = 180;
            case ExifInterface.ORIENTATION_ROTATE_270:
                orientation = 270;
        }
    } catch (Exception e) {
        Logger.e(e);
    }
    return orientation;
}
 
Example 4
Source File: XUtils.java    From FaceDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片属性:旋转的角度
 * 
 * @param path
 *          图片绝对路径
 * @return degree旋转的角度
 */
public 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 5
Source File: PictureUtil.java    From Swface with Apache License 2.0 6 votes vote down vote up
/**
 * 读取图片属性:旋转的角度
 *
 * @param path 图片绝对路径
 * @return degree 旋转角度
 */
public 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 6
Source File: Luban.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * obtain the image rotation angle
 *
 * @param path path of target image
 */
private int getImageSpinAngle(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: ImageHelper.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean isRotateNeed(String filepath) {
    try {
        ExifInterface exif = new ExifInterface(filepath);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
            case ExifInterface.ORIENTATION_ROTATE_180:
            case ExifInterface.ORIENTATION_ROTATE_90:
                return true;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 8
Source File: ImageHelper.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Bitmap correctRotate(String filepath, Bitmap bitmap) {

        try {
            ExifInterface ei = new ExifInterface(filepath);
            int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = rotateImage(bitmap, 270);
                    break;
            }
        } catch (IOException e) {
            return bitmap;
        }

        return bitmap;
    }
 
Example 9
Source File: TransformationUtils.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * Get the # of degrees an image must be rotated to match the given exif orientation.
 *
 * @param exifOrientation The exif orientation [1-8]
 * @return the number of degrees to rotate
 */
public static int getExifOrientationDegrees(int exifOrientation) {
    final int degreesToRotate;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_TRANSPOSE:
        case ExifInterface.ORIENTATION_ROTATE_90:
            degreesToRotate = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            degreesToRotate = 180;
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
        case ExifInterface.ORIENTATION_ROTATE_270:
            degreesToRotate = 270;
            break;
        default:
            degreesToRotate = 0;

    }
    return degreesToRotate;
}
 
Example 10
Source File: BitmapUtils.java    From ToolsFinal 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 11
Source File: PhotoUtils.java    From MyBlogDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 获取图片的旋转角度
 *
 * @param path 图片的绝对路径
 * @return 图片的旋转角度
 */
private 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;
}
 
Example 12
Source File: BitmapProcessing.java    From Effects-Pro with MIT License 6 votes vote down vote up
public static Bitmap modifyOrientation(Bitmap bitmap, String image_url) throws IOException {
	ExifInterface ei = new ExifInterface(image_url);
	int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

	switch (orientation) {
	case ExifInterface.ORIENTATION_ROTATE_90:
		return rotate(bitmap, 90);

	case ExifInterface.ORIENTATION_ROTATE_180:
		return rotate(bitmap, 180);

	case ExifInterface.ORIENTATION_ROTATE_270:
		return rotate(bitmap, 270);

	case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
		return flip(bitmap, true, false);

	case ExifInterface.ORIENTATION_FLIP_VERTICAL:
		return flip(bitmap, false, true);

	default:
		return bitmap;
	}
}
 
Example 13
Source File: ImageUtils.java    From FaceDetectCamera with Apache License 2.0 5 votes vote down vote up
public static Bitmap getBitmap(String filePath, int width, int height) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, options);
    options.inSampleSize = ImageUtils.calculateInSampleSize(options, width, height);
    options.inJustDecodeBounds = false;
    options.inPreferredConfig = Bitmap.Config.RGB_565;

    Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

    if (bitmap != null) {
        try {
            ExifInterface ei = new ExifInterface(filePath);
            int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = ImageUtils.rotate(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = ImageUtils.rotate(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = ImageUtils.rotate(bitmap, 270);
                    break;
                // etc.
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return bitmap;
}
 
Example 14
Source File: ExifHelper.java    From jpHolo 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 15
Source File: ExifHelper.java    From crosswalk-cordova-android 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 16
Source File: Utils.java    From SimpleCropView with MIT License 5 votes vote down vote up
public static int getExifOrientationFromAngle(int angle) {
  int normalizedAngle = angle % 360;
  switch (normalizedAngle) {
    case 0:
      return ExifInterface.ORIENTATION_NORMAL;
    case 90:
      return ExifInterface.ORIENTATION_ROTATE_90;
    case 180:
      return ExifInterface.ORIENTATION_ROTATE_180;
    case 270:
      return ExifInterface.ORIENTATION_ROTATE_270;
    default:
      return ExifInterface.ORIENTATION_NORMAL;
  }
}
 
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 Roid-Library with Apache License 2.0 5 votes vote down vote up
protected ExifInfo defineExifOrientation(String imageUri, String mimeType) {
    int rotation = 0;
    boolean flip = false;
    if ("image/jpeg".equalsIgnoreCase(mimeType) && Scheme.ofUri(imageUri) == Scheme.FILE) {
        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: ImageResizer.java    From react-native-pixel-color with MIT License 5 votes vote down vote up
/**
 * Convert metadata to degrees
 */
public static int getOrientation(ExifInterface exif) {
    int orientation = exif.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;
    }
}
 
Example 20
Source File: BitmapUtil.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
/**
 * load本地图片
 *
 * @param path
 * @param screenWidth
 * @return
 * @throws IOException
 */
public static Bitmap loadBitmap(String path, int screenWidth) {
    int degree = 0;
    int orientation;
    try {
        orientation = new ExifInterface(path).getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
    } catch (IOException e) {
        Log.e(TAG, "loadBitmap: ", 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;
    }
    BitmapFactory.Options opt = new BitmapFactory.Options();
    // 这个isjustdecodebounds很重要
    opt.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, opt);
    // 获取到这个图片的原始宽度和高度
    int picWidth = opt.outWidth;
    int picHeight = opt.outHeight;
    // isSampleSize是表示对图片的缩放程度,比如值为2图片的宽度和高度都变为以前的1/2
    opt.inSampleSize = 1;
    // 根据屏的大小和图片大小计算出缩放比例
    if (picWidth > picHeight) {
        if (picHeight > screenWidth)
            opt.inSampleSize = picHeight / screenWidth;
    } else {
        if (picWidth > screenWidth)
            opt.inSampleSize = picWidth / screenWidth;
    }
    // 这次再真正地生成一个有像素的,经过缩放了的bitmap
    opt.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeFile(path, opt);
    if (degree == 90 || degree == 180 || degree == 270) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }
    return bitmap;
}