Added in API level 8

ThumbnailUtils


open class ThumbnailUtils
kotlin.Any
   ↳ android.media.ThumbnailUtils

Utilities for generating visual thumbnails from files.

Summary

Constants
static Int

Constant used to indicate we should recycle the input in extractThumbnail(android.graphics.Bitmap,int,int,int) unless the output is the input.

Public constructors

Public methods
open static Bitmap?
createAudioThumbnail(filePath: String, kind: Int)

Create a thumbnail for given audio file.

open static Bitmap

Create a thumbnail for given audio file.

open static Bitmap?
createImageThumbnail(filePath: String, kind: Int)

Create a thumbnail for given image file.

open static Bitmap

Create a thumbnail for given image file.

open static Bitmap?
createVideoThumbnail(filePath: String, kind: Int)

Create a thumbnail for given video file.

open static Bitmap

Create a thumbnail for given video file.

open static Bitmap!
extractThumbnail(source: Bitmap!, width: Int, height: Int)

Creates a centered bitmap of the desired size.

open static Bitmap!
extractThumbnail(source: Bitmap!, width: Int, height: Int, options: Int)

Creates a centered bitmap of the desired size.

Constants

OPTIONS_RECYCLE_INPUT

Added in API level 8
static val OPTIONS_RECYCLE_INPUT: Int

Constant used to indicate we should recycle the input in extractThumbnail(android.graphics.Bitmap,int,int,int) unless the output is the input.

Value: 2

Public constructors

ThumbnailUtils

ThumbnailUtils()

Public methods

createAudioThumbnail

Added in API level 29
Deprecated in API level 29
open static fun createAudioThumbnail(
    filePath: String,
    kind: Int
): Bitmap?

Deprecated: Callers should migrate to using createAudioThumbnail(java.io.File,android.util.Size,android.os.CancellationSignal), as it offers more control over resizing and cancellation.

Create a thumbnail for given audio file.

Parameters
filePath String: The audio file. This value cannot be null.
kind Int: The desired thumbnail kind, such as android.provider.MediaStore.Images.Thumbnails#MINI_KIND.
Return
Bitmap? This value may be null.

createAudioThumbnail

Added in API level 29
open static fun createAudioThumbnail(
    file: File,
    size: Size,
    signal: CancellationSignal?
): Bitmap

Create a thumbnail for given audio file.

This method should only be used for files that you have direct access to; if you'd like to work with media hosted outside your app, consider using ContentResolver#loadThumbnail(Uri, Size, CancellationSignal) which enables remote providers to efficiently cache and invalidate thumbnails.

Parameters
file File: The audio file. This value cannot be null.
size Size: The desired thumbnail size. This value cannot be null.
signal CancellationSignal?: This value may be null.
Return
Bitmap This value cannot be null.
Exceptions
java.io.IOException If any trouble was encountered while generating or loading the thumbnail, or if CancellationSignal#cancel() was invoked.

createImageThumbnail

Added in API level 29
Deprecated in API level 29
open static fun createImageThumbnail(
    filePath: String,
    kind: Int
): Bitmap?

Deprecated: Callers should migrate to using createImageThumbnail(java.io.File,android.util.Size,android.os.CancellationSignal), as it offers more control over resizing and cancellation.

Create a thumbnail for given image file.

Parameters
filePath String: The image file. This value cannot be null.
kind Int: The desired thumbnail kind, such as android.provider.MediaStore.Images.Thumbnails#MINI_KIND.
Return
Bitmap? This value may be null.

createImageThumbnail

Added in API level 29
open static fun createImageThumbnail(
    file: File,
    size: Size,
    signal: CancellationSignal?
): Bitmap

Create a thumbnail for given image file.

This method should only be used for files that you have direct access to; if you'd like to work with media hosted outside your app, consider using ContentResolver#loadThumbnail(Uri, Size, CancellationSignal) which enables remote providers to efficiently cache and invalidate thumbnails.

Parameters
file File: The image file. This value cannot be null.
size Size: The desired thumbnail size. This value cannot be null.
signal CancellationSignal?: This value may be null.
Return
Bitmap This value cannot be null.
Exceptions
java.io.IOException If any trouble was encountered while generating or loading the thumbnail, or if CancellationSignal#cancel() was invoked.

createVideoThumbnail

Added in API level 8
Deprecated in API level 29
open static fun createVideoThumbnail(
    filePath: String,
    kind: Int
): Bitmap?

Deprecated: Callers should migrate to using createVideoThumbnail(java.io.File,android.util.Size,android.os.CancellationSignal), as it offers more control over resizing and cancellation.

Create a thumbnail for given video file.

Parameters
filePath String: The video file. This value cannot be null.
kind Int: The desired thumbnail kind, such as android.provider.MediaStore.Images.Thumbnails#MINI_KIND.
Return
Bitmap? This value may be null.

createVideoThumbnail

Added in API level 29
open static fun createVideoThumbnail(
    file: File,
    size: Size,
    signal: CancellationSignal?
): Bitmap

Create a thumbnail for given video file.

This method should only be used for files that you have direct access to; if you'd like to work with media hosted outside your app, consider using ContentResolver#loadThumbnail(Uri, Size, CancellationSignal) which enables remote providers to efficiently cache and invalidate thumbnails.

Parameters
file File: The video file. This value cannot be null.
size Size: The desired thumbnail size. This value cannot be null.
signal CancellationSignal?: This value may be null.
Return
Bitmap This value cannot be null.
Exceptions
java.io.IOException If any trouble was encountered while generating or loading the thumbnail, or if CancellationSignal#cancel() was invoked.

extractThumbnail

Added in API level 8
open static fun extractThumbnail(
    source: Bitmap!,
    width: Int,
    height: Int
): Bitmap!

Creates a centered bitmap of the desired size.

Parameters
source Bitmap!: original bitmap source
width Int: targeted width
height Int: targeted height

extractThumbnail

Added in API level 8
open static fun extractThumbnail(
    source: Bitmap!,
    width: Int,
    height: Int,
    options: Int
): Bitmap!

Creates a centered bitmap of the desired size.

Parameters
source Bitmap!: original bitmap source
width Int: targeted width
height Int: targeted height
options Int: options used during thumbnail extraction