Java Code Examples for android.media.ExifInterface#ORIENTATION_NORMAL

The following examples show how to use android.media.ExifInterface#ORIENTATION_NORMAL . 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: UGCImageIntentResultHandler.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private Bitmap normalizeImage(String filePath, Bitmap image) {

        try {
            ExifInterface ei = new ExifInterface(filePath);
            int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

            Bitmap transformedImage;
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    logger.debug("Correcting image rotation 90 degrees.");
                    transformedImage = new RotateTransformation(90).transform(image);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    logger.debug("Correcting image rotation 180 degrees.");
                    transformedImage = new RotateTransformation(180).transform(image);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    logger.debug("Correcting image rotation 270 degrees.");
                    transformedImage = new RotateTransformation(270).transform(image);
                    break;
                case ExifInterface.ORIENTATION_NORMAL:
                    logger.debug("Image is correctly oriented; no transformation required.");
                    return image;
                default:
                    logger.warn("Image is not correctly oriented, but no correction is implemented for orientation: " + orientation);
                    return image;
            }

            if (image != null) {
                image.recycle();
            }

            return transformedImage;

        } catch (IOException e) {
            logger.error("Failed to read EXIF information on captured photo; image may be rotated.");
        }

        return image;
    }
 
Example 2
Source File: CloseableStaticBitmapTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setUp() {
  mBitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
  ResourceReleaser<Bitmap> releaser = SimpleBitmapReleaser.getInstance();
  mCloseableStaticBitmap =
      new CloseableStaticBitmap(
          mBitmap,
          releaser,
          ImmutableQualityInfo.FULL_QUALITY,
          0,
          ExifInterface.ORIENTATION_NORMAL);
}
 
Example 3
Source File: Texture.java    From smartGL with Apache License 2.0 5 votes vote down vote up
public static Bitmap loadAndTurnAndResize(Context context, String pictureName, int approxWidth) {
	try {
		final ExifInterface exif = new ExifInterface(pictureName);
		final int srcWidth = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, approxWidth);
		final int subSample = (srcWidth / approxWidth);
		BitmapFactory.Options resizeOptions = new BitmapFactory.Options();
		resizeOptions.inSampleSize = subSample;
		Bitmap bitmap = BitmapFactory.decodeFile(pictureName, resizeOptions);
		if (bitmap != null) {
			final int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
			if (orientation != ExifInterface.ORIENTATION_NORMAL) {
				int angle = 0;
				if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
					angle = 90;
				} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
					angle = 180;
				} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
					angle = 270;
				}
				if (angle != 0f) {
					Matrix matrix = new Matrix();
					matrix.preRotate(angle);
					Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
					bitmap.recycle();
					return rotatedBitmap;
				}
			}
		}
		return bitmap;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: BaseImageDecoder.java    From mobile-manager-tool with MIT License 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 5
Source File: ExifHelper.java    From CordovaYoutubeVideoPlayer 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 6
Source File: BaseImageDecoder.java    From Android-Application-ZJB 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 7
Source File: ExifHelper.java    From reader 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 8
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 9
Source File: OrientedDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
protected void onBoundsChange(Rect bounds) {
  Drawable underlyingDrawable = getCurrent();
  if (mRotationAngle > 0
      || (mExifOrientation != ExifInterface.ORIENTATION_UNDEFINED
          && mExifOrientation != ExifInterface.ORIENTATION_NORMAL)) {
    switch (mExifOrientation) {
      case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        mRotationMatrix.setScale(-1, 1);
        break;
      case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        mRotationMatrix.setScale(1, -1);
        break;
      case ExifInterface.ORIENTATION_TRANSPOSE:
        mRotationMatrix.setRotate(270, bounds.centerX(), bounds.centerY());
        mRotationMatrix.postScale(1, -1);
        break;
      case ExifInterface.ORIENTATION_TRANSVERSE:
        mRotationMatrix.setRotate(270, bounds.centerX(), bounds.centerY());
        mRotationMatrix.postScale(-1, 1);
        break;
      default:
        mRotationMatrix.setRotate(mRotationAngle, bounds.centerX(), bounds.centerY());
        break;
    }

    // Set the rotated bounds on the underlying drawable
    mTempMatrix.reset();
    mRotationMatrix.invert(mTempMatrix);
    mTempRectF.set(bounds);
    mTempMatrix.mapRect(mTempRectF);
    underlyingDrawable.setBounds(
        (int) mTempRectF.left,
        (int) mTempRectF.top,
        (int) mTempRectF.right,
        (int) mTempRectF.bottom);
  } else {
    underlyingDrawable.setBounds(bounds);
  }
}
 
Example 10
Source File: ExifHelper.java    From showCaseCordova 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 11
Source File: ExifUtil.java    From YiBo with Apache License 2.0 5 votes vote down vote up
public static int getExifRotation(String imgPath) {
	int rotate = 0;
    try {
        ExifInterface exif = new ExifInterface(imgPath);
        String rotationAmount = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
        if (!TextUtils.isEmpty(rotationAmount)) {
            int rotationParam = Integer.parseInt(rotationAmount);
            switch (rotationParam) {
            case ExifInterface.ORIENTATION_NORMAL:
            	rotate = 0;
            	break;
            case ExifInterface.ORIENTATION_ROTATE_90:
            	rotate = 90;
            	break;
            case ExifInterface.ORIENTATION_ROTATE_180:
            	rotate = 180;
            	break;
            case ExifInterface.ORIENTATION_ROTATE_270:
            	rotate = 270;
            	break;
            default:
            	rotate = 0;
            	break;
            }
        }
    } catch (Exception e) {
        Logger.debug("ExifUtil", e);
    }
    
    return rotate;
}
 
Example 12
Source File: ImageResizer.java    From cordova-plugin-image-resizer with MIT License 5 votes vote down vote up
/**
* Gets the image rotation from the image EXIF Data
*
* @param uriString the URI of the image to get the rotation for
* @return ExifInterface.ORIENTATION_* representation of the rotation
*/
private int getRotation(String uriString){
  try {
    ExifInterface exif = new ExifInterface(uriString);
    return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  } catch (IOException e) {
    return ExifInterface.ORIENTATION_NORMAL;
  }
}
 
Example 13
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 14
Source File: ExifHelper.java    From reader with MIT License 4 votes vote down vote up
public void resetOrientation() {
    this.orientation = "" + ExifInterface.ORIENTATION_NORMAL;
}
 
Example 15
Source File: ImageUtils.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Bitmap rotateBitmap(Bitmap bitmap, int orientation) {
    Matrix matrix = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return bitmap;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.setScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.setRotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.setRotate(180);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            matrix.setRotate(90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.setRotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            matrix.setRotate(-90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.setRotate(-90);
            break;
        default:
            return bitmap;
    }

    try {
        Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        bitmap.recycle();
        return bmRotated;
    } catch (OutOfMemoryError ignore) {
        return null;
    }
}
 
Example 16
Source File: ExifHelper.java    From bluemix-parking-meter with MIT License 4 votes vote down vote up
public void resetOrientation() {
    this.orientation = "" + ExifInterface.ORIENTATION_NORMAL;
}
 
Example 17
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the EXIF angle after rotating the image.
 *
 * @param originalAngle The original EXIF angle
 * @param rotationAngle The EXIF style rotation angle
 * @return the EXIF angle after rotation
 */
public static short getRotatedExifAngle(final Short originalAngle, final short rotationAngle) {
	if (originalAngle == null) {
		return rotationAngle;
	}

	switch (originalAngle) {
	case ExifInterface.ORIENTATION_NORMAL:
		return rotationAngle;
	case ExifInterface.ORIENTATION_ROTATE_90:
		switch (rotationAngle) {
		case ExifInterface.ORIENTATION_ROTATE_90:
			return ExifInterface.ORIENTATION_ROTATE_180;
		case ExifInterface.ORIENTATION_ROTATE_180:
			return ExifInterface.ORIENTATION_ROTATE_270;
		case ExifInterface.ORIENTATION_ROTATE_270:
			return ExifInterface.ORIENTATION_NORMAL;
		default:
			return originalAngle;
		}
	case ExifInterface.ORIENTATION_ROTATE_180:
		switch (rotationAngle) {
		case ExifInterface.ORIENTATION_ROTATE_90:
			return ExifInterface.ORIENTATION_ROTATE_270;
		case ExifInterface.ORIENTATION_ROTATE_180:
			return ExifInterface.ORIENTATION_NORMAL;
		case ExifInterface.ORIENTATION_ROTATE_270:
			return ExifInterface.ORIENTATION_ROTATE_90;
		default:
			return originalAngle;
		}
	case ExifInterface.ORIENTATION_ROTATE_270:
		switch (rotationAngle) {
		case ExifInterface.ORIENTATION_ROTATE_90:
			return ExifInterface.ORIENTATION_NORMAL;
		case ExifInterface.ORIENTATION_ROTATE_180:
			return ExifInterface.ORIENTATION_ROTATE_90;
		case ExifInterface.ORIENTATION_ROTATE_270:
			return ExifInterface.ORIENTATION_ROTATE_180;
		default:
			return originalAngle;
		}
	default:
		return originalAngle;
	}
}
 
Example 18
Source File: ExifHelper.java    From cordova-android-chromeview with Apache License 2.0 4 votes vote down vote up
public void resetOrientation() {
    this.orientation = "" + ExifInterface.ORIENTATION_NORMAL;
}
 
Example 19
Source File: DefaultDrawableFactory.java    From fresco with MIT License 4 votes vote down vote up
private static boolean hasTransformableExifOrientation(
    CloseableStaticBitmap closeableStaticBitmap) {
  return closeableStaticBitmap.getExifOrientation() != ExifInterface.ORIENTATION_NORMAL
      && closeableStaticBitmap.getExifOrientation() != ExifInterface.ORIENTATION_UNDEFINED;
}
 
Example 20
Source File: UserPicture.java    From SO-2169649 with Apache License 2.0 4 votes vote down vote up
private boolean getInformationFromFileSystem() throws IOException {
    path = uri.getPath();

    if (path == null)
        return false;

    ExifInterface exif = new ExifInterface(path);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_NORMAL);

    this.orientation = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            /* Identity matrix */
            break;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            this.orientation.setScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            this.orientation.setRotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            this.orientation.setScale(1, -1);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            this.orientation.setRotate(90);
            this.orientation.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            this.orientation.setRotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            this.orientation.setRotate(-90);
            this.orientation.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            this.orientation.setRotate(-90);
            break;
    }

    return true;
}