ImagenMaskReference

@PublicPreviewAPI
abstract class ImagenMaskReference : 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

Public companion functions

List<ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement
)

This function is deprecated. All Imagen models are deprecated.

List<ImagenReferenceImage>
generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement,
    dilation: Double
)

This function is deprecated. All Imagen models are deprecated.

Public companion functions

generateMaskAndPadForOutpainting

fun generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER
): List<ImagenReferenceImage>

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
image: ImagenInlineImage

the original image

newDimensions: Dimensions

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

newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER

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

generateMaskAndPadForOutpainting

fun generateMaskAndPadForOutpainting(
    image: ImagenInlineImage,
    newDimensions: Dimensions,
    newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER,
    dilation: Double = 0.01
): List<ImagenReferenceImage>

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
image: ImagenInlineImage

the original image

newDimensions: Dimensions

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

newPosition: ImagenImagePlacement = ImagenImagePlacement.CENTER

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

dilation: Double = 0.01

the dilation for the outpainting mask. See: ImagenRawMask.