Esempio n. 1
0
  /**
   * Decodes a bitmap from a file containing it minimizing the memory use, known that the bitmap
   * will be drawn in a surface of reqWidth x reqHeight
   *
   * @param srcPath Absolute path to the file containing the image.
   * @param reqWidth Width of the surface where the Bitmap will be drawn on, in pixels.
   * @param reqHeight Height of the surface where the Bitmap will be drawn on, in pixels.
   * @return
   */
  public static Bitmap decodeSampledBitmapFromFile(String srcPath, int reqWidth, int reqHeight) {

    // set desired options that will affect the size of the bitmap
    final Options options = new Options();
    options.inScaled = true;
    options.inPurgeable = true;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
      options.inPreferQualityOverSpeed = false;
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
      options.inMutable = false;
    }

    // make a false load of the bitmap to get its dimensions
    options.inJustDecodeBounds = true;

    BitmapFactory.decodeFile(srcPath, options);

    // calculate factor to subsample the bitmap
    options.inSampleSize = calculateSampleFactor(options, reqWidth, reqHeight);

    // decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(srcPath, options);
  }
Esempio n. 2
0
 @TargetApi(10)
 private void copyOptions10(Options srcOptions, Options destOptions) {
   destOptions.inPreferQualityOverSpeed = srcOptions.inPreferQualityOverSpeed;
 }