code: public static Bitmap loadThumbnail(@NonNull Context context, @DrawableRes final int resourceId,
                                         final int maxWidth, final int maxHeight) throws IOException {
          Pair<Integer, Integer> imageDimensions = getImageDimensions(context, resourceId);
          int sampleSize = getSampleSize(imageDimensions, maxWidth, maxHeight);
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = false;
          options.inSampleSize = sampleSize;
          Bitmap thumbnail =
                  BitmapFactory.decodeResource(context.getResources(), resourceId, options);
  
          if (thumbnail == null) {
              throw new IOException("Failed to decode image resource with id " + resourceId);
          }
  
          return thumbnail;
      }
docs: Loads a downsampled thumbnail of a specific image resource while maintaining its aspect
  ratio.
  
  @param context
  The context, which should be used, as an instance of the class {@link Context}. The
  context may not be null
  @param resourceId
  The resource id of the image resource, which should be loaded, as an {@link Integer}
  value. The resource id must correspond to a valid drawable resource
  @param maxWidth
  The maximum width of the thumbnail in pixels as an {@link Integer} value. The maximum
  width must be at least 1
  @param maxHeight
  The maximum height of the thumbnail in pixels as an {@link Integer} value. The
  maximum height must be at least 1
  @return The thumbnail, which has been loaded, as an instance of the class {@link Bitmap}
  @throws IOException
  The exception, which is thrown, if an error occurs while decoding the image resource