Exemplo n.º 1
1
 /**
  * Deposit in the province read images, width is high, the greater the picture clearer, but also
  * the memory
  *
  * @param imagePath Pictures in the path of the memory card
  * @param maxWidth The highest limit value target width
  * @param maxHeight The highest limit value target height
  * @return
  */
 public Bitmap readImage(String imagePath, int maxWidth, int maxHeight) {
   File imageFile = new File(imagePath);
   if (imageFile.exists()) {
     try {
       BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(imageFile));
       BitmapFactory.Options options = new BitmapFactory.Options();
       options.inJustDecodeBounds = true;
       BitmapFactory.decodeStream(inputStream, null, options);
       inputStream.close();
       int i = 0;
       while (true) {
         if ((options.outWidth >> i <= maxWidth) && (options.outHeight >> i <= maxHeight)) {
           inputStream = new BufferedInputStream(new FileInputStream(new File(imagePath)));
           options.inSampleSize = (int) Math.pow(2.0, i);
           options.inJustDecodeBounds = false;
           Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, options);
           inputStream.close();
           return bitmap;
         }
         i += 1;
       }
     } catch (IOException e) {
       Logger.e("This path does not exist" + imagePath, e);
     }
   }
   return null;
 }