コード例 #1
0
ファイル: MTKImageView.java プロジェクト: 4Fwolf/mt6572_x201
 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;
 }
コード例 #2
0
ファイル: ImageManager.java プロジェクト: hhxx12ttxs/JinXi
  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;
  }
コード例 #3
0
  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;
  }
コード例 #4
0
 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;
 }
コード例 #5
0
 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;
 }
コード例 #6
0
  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;
  }
コード例 #7
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;
 }
コード例 #8
0
ファイル: BitmapUtils.java プロジェクト: shepherd1st/xiaotoon
 /**
  * 读取图片的旋转的角度
  *
  * @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;
 }
コード例 #9
0
ファイル: BitmapTool.java プロジェクト: huxin-89/AllInOne
  /**
   * 获取图片的旋转角度
   *
   * @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;
  }
コード例 #10
0
  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);
  }
コード例 #11
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;
  }
コード例 #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;
 }
コード例 #13
0
ファイル: MainActivity.java プロジェクト: huluwa/AndroidBook
 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;
 }
コード例 #14
0
 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);
 }
コード例 #15
0
ファイル: BitmapUtil.java プロジェクト: tgf229/THYProperty
  /**
   * <得到 图片旋转 的角度> <功能详细描述>
   *
   * @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;
  }
コード例 #16
0
ファイル: AppUtil.java プロジェクト: Guruev/DatingApp
  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;
  }
コード例 #17
0
 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());
     }
   }
 }
コード例 #18
0
    @Override
    public void saveRequest() {
      // title, file path, temp file path is ready
      FileOutputStream out = null;
      try {
        // Write to a temporary file and rename it to the final name.
        // This
        // avoids other apps reading incomplete data.
        out = new FileOutputStream(mTempFilePath);
        out.write(mData);
        out.close();
        new File(mTempFilePath).renameTo(new File(mFilePath));
      } catch (IOException e) {
        Log.e(TAG, "[saveRequest]PanoOperator,Failed to write image", e);
      } finally {
        if (out != null) {
          try {
            out.close();
          } catch (IOException e) {
            Log.e(TAG, "[saveRequest]PanoOperator,exception:", e);
          }
        }
      }
      mDataSize = new File(mFilePath).length();
      try {
        ExifInterface exif = new ExifInterface(mFilePath);
        int orientation = Util.getExifOrientation(exif);
        int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
        int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
        mWidth = width;
        mHeight = height;
        mOrientation = orientation;
      } catch (IOException ex) {
        Log.e(TAG, "[saveRequest]PanoOperator,cannot read exif:", ex);
      }
      if (null == mFileName) {
        mTitle = createName(mFileType, mDateTaken, mGroupIndex);
        mFileName = Storage.generateFileName(mTitle, mTempPictureType);
        Log.i(TAG, "[saveRequest]PhotoOperator,mFileName = " + mFileName);
      }
      mMimeType = Storage.generateMimetype(mTitle, mTempPictureType);

      saveImageToDatabase(this);
    }
コード例 #19
0
 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;
 }
コード例 #20
0
ファイル: BitmapUtils.java プロジェクト: asifdahir/nscloud
  /**
   * 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;
  }
コード例 #21
0
  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);
  }
コード例 #22
0
  /**
   * Returns a human-readable string describing the white balance value. Returns empty string if
   * there is no white balance value or it is not recognized.
   */
  private static String getWhiteBalanceString(ExifInterface exif) {
    int whitebalance = exif.getAttributeInt(ExifInterface.TAG_WHITE_BALANCE, -1);
    if (whitebalance == -1) return "";

    switch (whitebalance) {
      case ExifInterface.WHITEBALANCE_AUTO:
        return "Auto";
      case ExifInterface.WHITEBALANCE_MANUAL:
        return "Manual";
      default:
        return "";
    }
  }
コード例 #23
0
 private void checkDataProperty() {
   ExifInterface exif = null;
   try {
     exif = new ExifInterface(mFilePath);
   } catch (IOException e) {
     e.printStackTrace();
   }
   if (exif != null) {
     mWidth = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
     mHeight = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
   } else {
     // In google default camera, it set picture size when
     // capture and onPictureTaken
     // Here we just set picture size in onPictureTaken.
     Size s = mContext.getParameters().getPictureSize();
     if (s != null) {
       mWidth = s.width;
       mHeight = s.height;
     }
   }
   Log.d(TAG, "[checkDataProperty] mWidth = " + mWidth + ",mHeight = " + mHeight);
 }
コード例 #24
0
  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;
  }
コード例 #25
0
ファイル: EXIF_helper.java プロジェクト: PicFrame/picframe
  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;
  }
コード例 #26
0
  protected Bitmap rotateImage(Bitmap bitmap) {
    Log.v(TAG, "Adjusting Rotation");
    // Rotation based on orientation
    try {
      ExifInterface exif = new ExifInterface(_path);
      int exifOrientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

      Log.v(TAG, "Orientation: " + exifOrientation);

      int rotate = 0;

      switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
          rotate = 90;
          break;
        case ExifInterface.ORIENTATION_ROTATE_180:
          rotate = 180;
          break;
        case ExifInterface.ORIENTATION_ROTATE_270:
          rotate = 270;
          break;
      }

      Log.v(TAG, "Rotation: " + rotate);

      if (rotate != 0) {

        // Getting width & height of the given image.
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();

        // Setting pre rotate
        Matrix mtx = new Matrix();
        mtx.preRotate(rotate);

        // Rotating Bitmap
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
      }

      // Convert to ARGB_8888, required by tesseract
      bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);

    } catch (IOException e) {
      Log.e(TAG, "Couldn't correct orientation: " + e.toString());
    }

    return bitmap;
  }
コード例 #27
0
 /**
  * Gets the degrees rotated.
  *
  * @return the degrees rotated
  */
 private int getDegreesRotated() {
   Logger.v(TAG, "getDegreesRotated entry");
   int degreesRotated = 0;
   int orientation = 0;
   String dataPath = mUri.getPath();
   try {
     ExifInterface exif = new ExifInterface(dataPath);
     orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
     degreesRotated = getExifRotation(orientation);
   } catch (IOException ex) {
     Logger.d(TAG, "getDegreesRotated cannot read exif");
     ex.printStackTrace();
   }
   Logger.v(TAG, "getDegreesRotated exit with degreesRotated: " + degreesRotated);
   return degreesRotated;
 }
コード例 #28
0
ファイル: ImageHelper.java プロジェクト: ravimaran/androidapp
  private static int getRotation(ExifInterface exif) {
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
    int rotate = 0;
    switch (orientation) {
      case 3:
        rotate = 180;
        break;
      case 6:
        rotate = 90;
        break;
      case 8:
        rotate = 270;
        break;
    }

    return rotate;
  }
コード例 #29
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 @Override
 protected int getImageOrientation() throws IOException {
   ExifInterface exif = new ExifInterface(mImageFile.getAbsolutePath());
   int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
   switch (orientation) {
     case ExifInterface.ORIENTATION_NORMAL:
       return 0;
     case ExifInterface.ORIENTATION_ROTATE_90:
       return 90;
     case ExifInterface.ORIENTATION_ROTATE_180:
       return 180;
     case ExifInterface.ORIENTATION_ROTATE_270:
       return 270;
     default:
       return 0;
   }
 }
コード例 #30
0
 public static int getPictureExifRotateAngle(String path) {
   int rotate = 0;
   try {
     ExifInterface ei = new ExifInterface(path);
     int ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
     if (ori == ExifInterface.ORIENTATION_ROTATE_180) {
       rotate = 180;
     } else if (ori == ExifInterface.ORIENTATION_ROTATE_270) {
       rotate = 270;
     } else if (ori == ExifInterface.ORIENTATION_ROTATE_90) {
       rotate = 90;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return rotate;
 }