/**
   * Decode and sample down a bitmap from a file to the requested width and height.
   *
   * @param filename The full path of the file to decode
   * @param reqWidth The requested width of the resulting bitmap
   * @param reqHeight The requested height of the resulting bitmap
   * @param cache The ImageCache used to find candidate bitmaps for use with inBitmap
   * @return A bitmap sampled down from the original with the same aspect ratio and dimensions that
   *     are equal to or greater than the requested width and height
   */
  public static Bitmap decodeSampledBitmapFromFile(
      String filename, int reqWidth, int reqHeight, ImageCache cache) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filename, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // If we're running on Honeycomb or newer, try to use inBitmap
    if (Utils.hasHoneycomb()) {
      addInBitmapOptions(options, cache);
    }

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filename, options);
  }
  /**
   * Decode and sample down a bitmap from resources to the requested width and height.
   *
   * @param res The resources object containing the image data
   * @param resId The resource id of the image data
   * @param reqWidth The requested width of the resulting bitmap
   * @param reqHeight The requested height of the resulting bitmap
   * @param cache The ImageCache used to find candidate bitmaps for use with inBitmap
   * @return A bitmap sampled down from the original with the same aspect ratio and dimensions that
   *     are equal to or greater than the requested width and height
   */
  public static Bitmap decodeSampledBitmapFromResource(
      Resources res, int resId, int reqWidth, int reqHeight, ImageCache cache) {

    // BEGIN_INCLUDE (read_bitmap_dimensions)
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    // END_INCLUDE (read_bitmap_dimensions)

    // If we're running on Honeycomb or newer, try to use inBitmap
    if (Utils.hasHoneycomb()) {
      addInBitmapOptions(options, cache);
    }

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
  }