ImagenMaskReference

@PublicPreviewAPI
public abstract class ImagenMaskReference extends ImagenReferenceImage

Known direct subclasses
ImagenBackgroundMask

This class is deprecated. All Imagen models are deprecated.

ImagenForegroundMask

This class is deprecated. All Imagen models are deprecated.

ImagenRawMask

This class is deprecated. All Imagen models are deprecated.

ImagenSemanticMask

This class is deprecated. All Imagen models are deprecated.


Represents a mask for Imagen editing. This image (generated or provided) should contain only black and white pixels, with black representing parts of the image which should not change.

Deprecation Notice: All Imagen models are deprecated and will shut down as early as June 2026. As a replacement, you can migrate your apps to use Gemini Image models (the 'Nano Banana' models)

Summary

Nested types

public static class ImagenMaskReference.Companion

Public methods

static final @NonNull List<@NonNull ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition
)

This method is deprecated. All Imagen models are deprecated.

static final @NonNull List<@NonNull ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition,
    double dilation
)

This method is deprecated. All Imagen models are deprecated.

Public methods

generateMaskAndPadForOutpainting

public static final @NonNull List<@NonNull ImagenReferenceImagegenerateMaskAndPadForOutpainting(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition
)

Generates two reference images of ImagenRawImage and ImagenRawMask. These images are generated in this order:

  • One ImagenRawImage containing the original image, padded out to the new dimensions with black pixels, with the original image placed at the given placement

  • One ImagenRawMask of the same dimensions containing white everywhere except at the placement original image. This is the format expected by Imagen for outpainting requests.

Deprecation Notice: All Imagen models are deprecated and will shut down as early as June 2026. As a replacement, you can migrate your apps to use Gemini Image models (the 'Nano Banana' models)

Parameters
@NonNull ImagenInlineImage image

the original image

@NonNull Dimensions newDimensions

the new dimensions for outpainting. These new dimensions must be more than the original image.

@NonNull ImagenImagePlacement newPosition

the placement of the original image within the new outpainted image.

generateMaskAndPadForOutpainting

public static final @NonNull List<@NonNull ImagenReferenceImagegenerateMaskAndPadForOutpainting(
    @NonNull ImagenInlineImage image,
    @NonNull Dimensions newDimensions,
    @NonNull ImagenImagePlacement newPosition,
    double dilation
)

Generates two reference images of ImagenRawImage and ImagenRawMask. These images are generated in this order:

  • One ImagenRawImage containing the original image, padded out to the new dimensions with black pixels, with the original image placed at the given placement

  • One ImagenRawMask of the same dimensions containing white everywhere except at the placement original image. This is the format expected by Imagen for outpainting requests.

Deprecation Notice: All Imagen models are deprecated and will shut down as early as June 2026. As a replacement, you can migrate your apps to use Gemini Image models (the 'Nano Banana' models)

Parameters
@NonNull ImagenInlineImage image

the original image

@NonNull Dimensions newDimensions

the new dimensions for outpainting. These new dimensions must be more than the original image.

@NonNull ImagenImagePlacement newPosition

the placement of the original image within the new outpainted image.

double dilation

the dilation for the outpainting mask. See: ImagenRawMask.