Skip to content Skip to sidebar Skip to footer

What Is The Right Point In My Code To Rotate An Landscape Image Captured In My App?

I don't have much experience working with the camera and files in general. I've integrated CameraKit's library to capture images, and this is my current code: captureButton.setOnCl

Solution 1:

  //SOLUTION 1->
  //find the Orientation Using ExifInterface
   try{
        File imageFile = new File(imagePath);
        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        int orientation = exif.getAttributeInt(
                            ExifInterface.TAG_ORIENTATION,
                            ExifInterface.ORIENTATION_NORMAL);

 //From the orientation value you can convert(Rotate) image according to orientation and can be set it to the ImageView later
         int rotate = 0;
         switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                 rotate = 270;
                 break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                 rotate = 180;
                 break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                 rotate = 90;
                 break;
          }
        }
   catch (Exception e) {
   }

  // Image rotation //
  Matrix matrix = new Matrix();
  matrix.postRotate(orientation);
  Bitmap cropped = Bitmap.createBitmap(scaled, x, y, width, height, matrix, true);  


// SOLUTION 2
ExifInterface oldExif = new ExifInterface(oldImagePath);
String exifOrientation = oldExif.getAttribute(ExifInterface.TAG_ORIENTATION);

if (exifOrientation != null) {
   ExifInterface newExif = new ExifInterface(imagePath);
  newExif.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation);
  newExif.saveAttributes();
}

Post a Comment for "What Is The Right Point In My Code To Rotate An Landscape Image Captured In My App?"