/**
   * 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,
      com.qicheng.business.ui.chat.utils.video.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);
  }
  /**
   * Decode and sample down a bitmap from a file input stream to the requested width and height.
   *
   * @param fileDescriptor The file descriptor to read from
   * @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 decodeSampledBitmapFromDescriptor(
      FileDescriptor fileDescriptor,
      int reqWidth,
      int reqHeight,
      com.qicheng.business.ui.chat.utils.video.ImageCache cache) {

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

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

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;

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

    return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
  }