ThumbnailUtils


public class ThumbnailUtils
extends Object

java.lang.Object
   ↳ android.media.ThumbnailUtils


Utilities for generating visual thumbnails from files.

Summary

Constants

int OPTIONS_RECYCLE_INPUT

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

ThumbnailUtils()

Public methods

static Bitmap createAudioThumbnail(String filePath, int kind)

This method was deprecated in API level 29. Callers should migrate to using createAudioThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal), as it offers more control over resizing and cancellation.

static Bitmap createAudioThumbnail(File file, Size size, CancellationSignal signal)

Create a thumbnail for given audio file.

static Bitmap createImageThumbnail(String filePath, int kind)

This method was deprecated in API level 29. Callers should migrate to using createImageThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal), as it offers more control over resizing and cancellation.

static Bitmap createImageThumbnail(File file, Size size, CancellationSignal signal)

Create a thumbnail for given image file.

static Bitmap createVideoThumbnail(String filePath, int kind)

This method was deprecated in API level 29. Callers should migrate to using createVideoThumbnail(java.io.File, android.util.Size, android.os.CancellationSignal), as it offers more control over resizing and cancellation.

static Bitmap createVideoThumbnail(File file, Size size, CancellationSignal signal)

Create a thumbnail for given video file.

static Bitmap extractThumbnail(Bitmap source, int width, int height, int options)

Creates a centered bitmap of the desired size.

static Bitmap extractThumbnail(Bitmap source, int width, int height)

Creates a centered bitmap of the desired size.

Inherited methods

Constants

OPTIONS_RECYCLE_INPUT

Added in API level 8
public static final int OPTIONS_RECYCLE_INPUT

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

Constant Value: 2 (0x00000002)

Public constructors

ThumbnailUtils

public ThumbnailUtils ()

Public methods

createAudioThumbnail

Added in API level 29
Deprecated in API level 29
public static Bitmap createAudioThumbnail (String filePath, 
                int kind)

This method was deprecated in API level 29.
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 MediaStore.Images.Thumbnails.MINI_KIND.

Returns
Bitmap This value may be null.

createAudioThumbnail

Added in API level 29
public static Bitmap createAudioThumbnail (File file, 
                Size size, 
                CancellationSignal signal)

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.

Returns
Bitmap This value cannot be null.

Throws
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
public static Bitmap createImageThumbnail (String filePath, 
                int kind)

This method was deprecated in API level 29.
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 MediaStore.Images.Thumbnails.MINI_KIND.

Returns
Bitmap This value may be null.

createImageThumbnail

Added in API level 29
public static Bitmap createImageThumbnail (File file, 
                Size size, 
                CancellationSignal signal)

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.

Returns
Bitmap This value cannot be null.

Throws
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
public static Bitmap createVideoThumbnail (String filePath, 
                int kind)

This method was deprecated in API level 29.
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 MediaStore.Images.Thumbnails.MINI_KIND.

Returns
Bitmap This value may be null.

createVideoThumbnail

Added in API level 29
public static Bitmap createVideoThumbnail (File file, 
                Size size, 
                CancellationSignal signal)

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.

Returns
Bitmap This value cannot be null.

Throws
IOException If any trouble was encountered while generating or loading the thumbnail, or if CancellationSignal.cancel() was invoked.

extractThumbnail

Added in API level 8
public static Bitmap extractThumbnail (Bitmap source, 
                int width, 
                int height, 
                int options)

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

Returns
Bitmap

extractThumbnail

Added in API level 8
public static Bitmap extractThumbnail (Bitmap source, 
                int width, 
                int height)

Creates a centered bitmap of the desired size.

Parameters
source Bitmap: original bitmap source

width int: targeted width

height int: targeted height

Returns
Bitmap