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);
 }
 public static int getExifOrientation(String filepath) { // YOUR MEDIA PATH AS STRING
   int degree = 0;
   ExifInterface exif = null;
   try {
     exif = new ExifInterface(filepath);
   } catch (IOException ex) {
     ex.printStackTrace();
   }
   if (exif != null) {
     int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
     if (orientation != -1) {
       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;
       }
       Log.d("degree", String.valueOf(degree));
     }
   }
   return degree;
 }
Example #3
0
 private Bitmap decodeAndRotate(String photoPaht) {
   Bitmap bmp = BitmapFactory.decodeFile(photoPaht);
   getContentResolver().notifyChange(Uri.parse("file://" + IMAGE_PATH), null);
   int rotate = 0;
   try {
     ExifInterface exif = new ExifInterface(photoPaht);
     int orientation =
         exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
     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) {
     e.printStackTrace();
   }
   Matrix matrix = new Matrix();
   matrix.postRotate(rotate);
   Bitmap rotateBitmap =
       Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
   return rotateBitmap;
 }
Example #4
0
 private int decodeDegreeInfo(Uri uri) {
   InputStream inputForRotate = null;
   int orientation = 0;
   int degree = 0;
   try {
     inputForRotate = mContext.getContentResolver().openInputStream(uri);
     if (inputForRotate != null) {
       ExifInterface exif = new ExifInterface(inputForRotate);
       if (exif != null) {
         orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
         degree = getExifRotation(orientation);
       }
     }
   } catch (FileNotFoundException e) {
     Log.e("MTKImageView", e.getMessage(), e);
   } catch (IOException e) {
     Log.e("MTKImageView", e.getMessage(), e);
   } finally {
     if (inputForRotate != null) {
       try {
         inputForRotate.close();
       } catch (Exception e) {
         Log.e("MTKImageView", e.getMessage(), e);
       }
     }
   }
   return degree;
 }
 public static int getExifOrientation(String filepath) {
   int degree = 0;
   ExifInterface exif = null;
   try {
     exif = new ExifInterface(filepath);
   } catch (IOException ex) {
   }
   if (exif != null) {
     int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
     if (orientation != -1) {
       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;
       }
     }
   }
   return degree;
 }
Example #6
0
  public static int getImageOrientation(String imagePath) {
    int rotate = 0;
    try {

      File imageFile = new File(imagePath);
      ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
      int orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

      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 (IOException e) {
      e.printStackTrace();
    }
    return rotate;
  }
Example #7
0
  /**
   * <得到 图片旋转 的角度> <功能详细描述>
   *
   * @param filepath
   * @return
   * @see [类、类#方法、类#成员]
   */
  private static int getExifOrientation(String filePath) {
    int degree = 0;
    try {
      ExifInterface exif = new ExifInterface(filePath);
      int result =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
      switch (result) {
        case ExifInterface.ORIENTATION_ROTATE_90:
          degree = 90;
          break;

        case ExifInterface.ORIENTATION_ROTATE_180:
          degree = 180;
          break;

        case ExifInterface.ORIENTATION_ROTATE_270:
          degree = 270;
          break;

        default:
          break;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return degree;
  }
  private static void showExifInformation(IImage image, View d, Activity activity) {
    ExifInterface exif = getExif(image);
    if (exif == null) {
      hideExifInformation(d);
      return;
    }

    String value = exif.getAttribute(ExifInterface.TAG_MAKE);
    if (value != null) {
      setDetailsValue(d, value, R.id.details_make_value);
    } else {
      hideDetailsRow(d, R.id.details_make_row);
    }

    value = exif.getAttribute(ExifInterface.TAG_MODEL);
    if (value != null) {
      setDetailsValue(d, value, R.id.details_model_value);
    } else {
      hideDetailsRow(d, R.id.details_model_row);
    }

    value = getWhiteBalanceString(exif);
    if (value != null && !value.equals(EMPTY_STRING)) {
      setDetailsValue(d, value, R.id.details_whitebalance_value);
    } else {
      hideDetailsRow(d, R.id.details_whitebalance_row);
    }

    setLatLngDetails(d, activity, exif);
  }
  public static int getCameraPhotoOrientation(Context context, Uri imageUri) {
    int rotate = 0;
    try {
      context.getContentResolver().notifyChange(imageUri, null);
      File imageFile = new File(imageUri.getPath());
      ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
      int orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

      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) {
      e.printStackTrace();
    }
    return rotate;
  }
Example #10
0
  /**
   * 读取图片属性:旋转的角度 add by Daisw
   *
   * @param srcPath 图片绝对路径
   * @return degree 旋转的角度
   */
  public static int getImageDegree(String srcPath) {

    int degree = 0;

    try {

      ExifInterface exifInterface = new ExifInterface(srcPath);
      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 (Throwable t) {

      DebugLog.e(TAG, t.getLocalizedMessage());
    }

    return degree;
  }
  public double getDegree(ExifInterface exif, int lat) {
    String attrLATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    String attrLATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    String attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    String attrLONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    double Latitude = 0;
    double Longitude = 0;

    if ((attrLATITUDE != null)
        && (attrLATITUDE_REF != null)
        && (attrLONGITUDE != null)
        && (attrLONGITUDE_REF != null)) {

      if (attrLATITUDE_REF.equals("N")) {
        Latitude = convertToDegree(attrLATITUDE);
      } else {
        Latitude = 0 - convertToDegree(attrLATITUDE);
      }

      if (attrLONGITUDE_REF.equals("E")) {
        Longitude = convertToDegree(attrLONGITUDE);
      } else {
        Longitude = 0 - convertToDegree(attrLONGITUDE);
      }
    }
    if (lat == 1) return Latitude;
    else return Longitude;
  };
Example #12
0
 public static int getExifOrientation(String filepath) {
   int degree = 0;
   ExifInterface exif = null;
   try {
     exif = new ExifInterface(filepath);
   } catch (IOException ex) {
     Log.e(TAG, "cannot read exif", ex);
   }
   if (exif != null) {
     int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
     if (orientation != -1) {
       // We only recognize a subset of orientation tag values.
       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;
       }
     }
   }
   return degree;
 }
Example #13
0
 /**
  * 判断原始素材的方向 (适用于相机拍摄的照片)
  *
  * @param path 图片的地址
  * @return angle->角度
  */
 @Override
 public int isRotatedImage(String path) {
   int angle = 0;
   try {
     ExifInterface exifInterface = new ExifInterface(path);
     int orientationPhoto =
         exifInterface.getAttributeInt("Orientation", ExifInterface.ORIENTATION_NORMAL);
     switch (orientationPhoto) {
       case ExifInterface.ORIENTATION_ROTATE_90:
         angle = 90;
         break;
       case ExifInterface.ORIENTATION_ROTATE_180:
         angle = 180;
         break;
       case ExifInterface.ORIENTATION_ROTATE_270:
         angle = 270;
         break;
       default:
         angle = 0;
         break;
     }
   } catch (IOException e) {
     Utils.debug(e.toString());
   }
   return angle;
 }
Example #14
0
  public int readPhotoRotateDegree(String imageUri) {
    int degree = 0;
    ExifInterface exif = null;
    try {
      exif = new ExifInterface(imageUri);
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (exif != null) {
      int orientation =
          exif.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;
      }
    }
    return degree;
  }
Example #15
0
 /**
  * 读取图片的旋转的角度
  *
  * @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;
       default:
         break;
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return degree;
 }
Example #16
0
  /**
   * 获取图片的旋转角度
   *
   * @param path
   * @return int @Title: readPictureDegree
   */
  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;
        default:
          degree = 0;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return degree;
  }
Example #17
0
  public static double[] getImageLocation(String filepath) {
    ExifInterface exif;
    try {
      exif = new ExifInterface(filepath);
      String LATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
      String LATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
      String LONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
      String LONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

      double[] result = new double[2];

      // in case of no data
      if (LATITUDE == null || LATITUDE_REF == null || LONGITUDE == null || LONGITUDE_REF == null)
        return new double[] {0.0, 0.0};

      if (LATITUDE_REF.equals("N")) {
        result[1] = convertToDegree(LATITUDE);
      } else {
        result[1] = 0 - convertToDegree(LATITUDE);
      }

      if (LONGITUDE_REF.equals("E")) {
        result[0] = convertToDegree(LONGITUDE);
      } else {
        result[0] = 0 - convertToDegree(LONGITUDE);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
  public static ApiThumbnailParam createThumbnailOnHeight(String filename, int height) {
    int degree = 0;
    try {
      ExifInterface exif = new ExifInterface(filename);
      int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
      if (orientation != -1) {
        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();
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);
    options.inSampleSize = (int) ((double) options.outHeight / (double) height);
    options.inJustDecodeBounds = false;

    Bitmap bm = BitmapFactory.decodeFile(filename, options);

    return new ApiThumbnailParam(
        createBitmapOnHeight(bm, height, degree), options.outWidth, options.outHeight);
  }
  public static Bitmap rotateImage(String path, Bitmap bm) {
    int orientation = 1;
    try {
      ExifInterface exifJpeg = new ExifInterface(path);
      orientation =
          exifJpeg.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

      ////			orientation = Integer.parseInt(exifJpeg.getAttribute(ExifInterface.TAG_ORIENTATION));
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (orientation != ExifInterface.ORIENTATION_NORMAL) {
      int width = bm.getWidth();
      int height = bm.getHeight();
      Matrix matrix = new Matrix();
      if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        matrix.postRotate(90);
      } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        matrix.postRotate(180);
      } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        matrix.postRotate(270);
      }
      return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
    }

    return bm;
  }
  /**
   * Read location information from image.
   *
   * @param imagePath : image absolute path
   * @return : loation information
   */
  public Location readGeoTagImage(String imagePath) {
    Location loc = new Location("");
    try {
      ExifInterface exif = new ExifInterface(imagePath);
      float[] latlong = new float[2];
      if (exif.getLatLong(latlong)) {
        loc.setLatitude(latlong[0]);
        loc.setLongitude(latlong[1]);
      }
      String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
      SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
      try {
        loc.setTime(fmt_Exif.parse(date).getTime());
      } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return loc;
  }
Example #21
0
  private void setInfoFromPict(Uri imageUri) {

    Bitmap resizedBitmap = RamenUtil.getResizedBitmap(imageUri, this);
    ((ImageView) findViewById(R.id.img_ramenpict)).setImageBitmap(resizedBitmap);

    ExifInterface exifInterface = null;
    try {
      ContentResolver resolver = getContentResolver();
      Cursor cursor = resolver.query(imageUri, null, null, null, null);
      cursor.moveToFirst();
      String filepath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));

      exifInterface = new ExifInterface(filepath);

    } catch (Exception e) {
      e.printStackTrace();
    }

    float[] latLong = new float[2];
    exifInterface.getLatLong(latLong);

    if (latLong[0] != 0.0f || latLong[1] != 0.0f) {
      ((EditText) findViewById(R.id.txt_lat)).setText(String.valueOf(latLong[0]));
      ((EditText) findViewById(R.id.txt_lon)).setText(String.valueOf(latLong[1]));
      Toast.makeText(this, "写真の位置情報を自動入力しました", Toast.LENGTH_SHORT).show();
    } else {
      Toast.makeText(this, "写真の位置情報が含まれていません。経度緯度を入力してください。", Toast.LENGTH_SHORT).show();
    }
  }
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == Activity.RESULT_OK) {
     if (requestCode == 13) {
       PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
       int orientation = 0;
       try {
         ExifInterface ei = new ExifInterface(currentPicturePath);
         int exif =
             ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
         switch (exif) {
           case ExifInterface.ORIENTATION_ROTATE_90:
             orientation = 90;
             break;
           case ExifInterface.ORIENTATION_ROTATE_180:
             orientation = 180;
             break;
           case ExifInterface.ORIENTATION_ROTATE_270:
             orientation = 270;
             break;
         }
       } catch (Exception e) {
         FileLog.e("tmessages", e);
       }
       final ArrayList<Object> arrayList = new ArrayList<>();
       arrayList.add(
           new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false));
       PhotoViewer.getInstance()
           .openPhotoForSelect(
               arrayList,
               0,
               1,
               new PhotoViewer.EmptyPhotoViewerProvider() {
                 @Override
                 public void sendButtonPressed(int index) {
                   String path = null;
                   MediaController.PhotoEntry photoEntry =
                       (MediaController.PhotoEntry) arrayList.get(0);
                   if (photoEntry.imagePath != null) {
                     path = photoEntry.imagePath;
                   } else if (photoEntry.path != null) {
                     path = photoEntry.path;
                   }
                   Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
                   processBitmap(bitmap);
                 }
               },
               null);
       AndroidUtilities.addMediaToGallery(currentPicturePath);
       currentPicturePath = null;
     } else if (requestCode == 14) {
       if (data == null || data.getData() == null) {
         return;
       }
       startCrop(null, data.getData());
     }
   }
 }
Example #23
0
 public static DateTime getImageCaptureTime(String filepath) {
   try {
     ExifInterface exif = new ExifInterface(filepath);
     String time = exif.getAttribute(ExifInterface.TAG_DATETIME);
     return DateTime.fromExifFormat(time);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
 private int getExifOrientation(String imagePath) {
   int orientation = 0;
   try {
     ExifInterface exif = new ExifInterface(imagePath);
     orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return orientation;
 }
Example #25
0
  /**
   * Rotate bitmap according to EXIF orientation. Cf.
   * http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
   *
   * @param bitmap Bitmap to be rotated
   * @param storagePath Path to source file of bitmap. Needed for EXIF information.
   * @return correctly EXIF-rotated bitmap
   */
  public static Bitmap rotateImage(Bitmap bitmap, String storagePath) {
    Bitmap resultBitmap = bitmap;

    try {
      ExifInterface exifInterface = new ExifInterface(storagePath);
      int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

      Matrix matrix = new Matrix();

      // 1: nothing to do

      // 2
      if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) {
        matrix.postScale(-1.0f, 1.0f);
      }
      // 3
      else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        matrix.postRotate(180);
      }
      // 4
      else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) {
        matrix.postScale(1.0f, -1.0f);
      }
      // 5
      else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) {
        matrix.postRotate(-90);
        matrix.postScale(1.0f, -1.0f);
      }
      // 6
      else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        matrix.postRotate(90);
      }
      // 7
      else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) {
        matrix.postRotate(90);
        matrix.postScale(1.0f, -1.0f);
      }
      // 8
      else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        matrix.postRotate(270);
      }

      // Rotate the bitmap
      resultBitmap =
          Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
      if (resultBitmap != bitmap) {
        bitmap.recycle();
      }
    } catch (Exception exception) {
      Log_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath);
    }
    return resultBitmap;
  }
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // robustness code
    if (mCallback == null
        || (mCameraCaptureURI == null && requestCode == REQUEST_LAUNCH_CAMERA)
        || (requestCode != REQUEST_LAUNCH_CAMERA && requestCode != REQUEST_LAUNCH_IMAGE_LIBRARY)) {
      return;
    }

    // user cancel
    if (resultCode != Activity.RESULT_OK) {
      mCallback.invoke(true, Arguments.createMap());
      return;
    }

    WritableMap response = Arguments.createMap();
    Uri uri = (requestCode == REQUEST_LAUNCH_CAMERA) ? mCameraCaptureURI : data.getData();

    // let's set data
    String realPath = getRealPathFromURI(uri);

    response.putString("path", uri.toString());
    response.putString("uri", realPath);
    if (!noData) {
      response.putString("data", getBase64StringFromFile(realPath));
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(realPath, options);
    response.putInt("width", options.outWidth);
    response.putInt("height", options.outHeight);

    try {
      ExifInterface exif = new ExifInterface(realPath);
      int orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
      boolean isVertical = true;
      switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
          isVertical = false;
          break;
        case ExifInterface.ORIENTATION_ROTATE_90:
          isVertical = false;
          break;
      }
      response.putBoolean("isVertical", isVertical);
    } catch (IOException e) {
      e.printStackTrace();
    }

    mCallback.invoke(false, response);
  }
  public static Bitmap createBitmapOnRectFast(String filename, int width, int height) {
    int inSampleSize = 1;
    BitmapFactory.Options options = new BitmapFactory.Options();

    int degree = 0;
    try {
      ExifInterface exif = new ExifInterface(filename);
      int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
      if (orientation != -1) {
        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();
    }

    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);
    double ratioWidth = (double) options.outWidth / (double) width;
    double ratioHeight = (double) options.outHeight / (double) height;

    if (ratioWidth > ratioHeight) {
      inSampleSize = (int) ratioHeight;
    } else {
      inSampleSize = (int) ratioWidth;
    }

    options.inSampleSize = inSampleSize;
    options.inJustDecodeBounds = false;

    Bitmap bm = BitmapFactory.decodeFile(filename, options);
    Bitmap result = null;
    if (bm != null) {
      if (bm.getWidth() != width && bm.getHeight() != height) {
        result = createBitmapOnRect(bm, width, height, degree);
      } else {
        result = bm;
      }
    }

    return result;
  }
  public JSONArray getPhoto(String fileName, int size) {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    Bitmap b = BitmapFactory.decodeFile(fileName);
    int width = b.getWidth();
    int height = b.getHeight();
    int isTall = 1;
    float ratio = ((float) width / height);
    int finalWidth = (int) ((float) size * ratio);
    int finalHeight = size;

    if (width > height) {
      isTall = 0;
      ratio = ((float) height / width);
      finalWidth = size;
      finalHeight = (int) ((float) size * ratio);
    }

    Bitmap out = Bitmap.createScaledBitmap(b, finalWidth, finalHeight, false);

    File file = new File(dir, "resize.png");
    FileOutputStream fOut;
    String base64 = "";
    try {
      fOut = new FileOutputStream(file);
      out.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
      base64 = encodeTobase64(out);
      fOut.flush();
      fOut.close();
      b.recycle();
      out.recycle();
    } catch (Exception el) {

    }
    JSONArray result = new JSONArray();
    JSONObject obj = new JSONObject();
    try {
      ExifInterface exif = new ExifInterface(fileName);

      obj.put("data", base64);
      obj.put("id", fileName);
      obj.put("date", exif.getAttribute(ExifInterface.TAG_DATETIME));
      obj.put("orientation", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
      obj.put("lat", getDegree(exif, 1));
      obj.put("lng", getDegree(exif, 0));
    } catch (Exception e) {
    }

    result.put(obj);
    return result;
  }
Example #29
0
  private static int getExifOrientation(String src) throws IOException {
    int orientation = ExifInterface.ORIENTATION_NORMAL;

    try {
      ExifInterface exif = new ExifInterface(src);
      orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    }
    return orientation;
  }
Example #30
0
  /**
   * Load the exif tags into the passed Bundle
   *
   * @param filepath
   * @param out
   * @return true if exif tags are loaded correctly
   */
  public static boolean loadAttributes(final String filepath, Bundle out) {
    ExifInterface e;
    try {
      e = new ExifInterface(filepath);
    } catch (IOException e1) {
      e1.printStackTrace();
      return false;
    }

    for (String tag : EXIF_TAGS) {
      out.putString(tag, e.getAttribute(tag));
    }
    return true;
  }