Struct Image

Image datatype.

struct Image ;

Native image datatype. Contains image data, which can be converted to a Texture, and several functions to interact with it. The maximum width and height for an Image are constant MAX_WIDTH and constant MAX_HEIGHT.

Properties

NameTypeDescription
data[get, set] DictionaryHolds all of the image's color data in a given format. See format constants.

Methods

NameDescription
_getData
_setData
blendRect Alpha-blends src_rect from src image to this image at coordinates dest.
blendRectMask Alpha-blends src_rect from src image to this image using mask image at coordinates dst. Alpha channels are required for both src and mask. dst pixels and src pixels will blend if the corresponding mask pixel's alpha value is not 0. src image and mask image must have the same size (width and height) but they can have different formats.
blitRect Copies src_rect from src image to this image at coordinates dst.
blitRectMask Blits src_rect area from src image to this image at the coordinates given by dst. src pixel is copied onto dst if the corresponding mask pixel's alpha value is not 0. src image and mask image must have the same size (width and height) but they can have different formats.
bumpmapToNormalmap Converts a bumpmap to a normalmap. A bumpmap provides a height offset per-pixel, while a normalmap provides a normal direction per pixel.
clearMipmaps Removes the image's mipmaps.
compress Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available. See compressmode and compresssource constants.
convert Converts the image's format. See format constants.
copyFrom Copies src image to this image.
create Creates an empty image of given size and format. See format constants. If use_mipmaps is true then generate mipmaps for this image. See the generateMipmaps.
createFromData Creates a new image of given size and format. See format constants. Fills the image with the given raw data. If use_mipmaps is true then generate mipmaps for this image. See the generateMipmaps.
crop Crops the image to the given width and height. If the specified size is larger than the current size, the extra area is filled with black pixels.
decompress Decompresses the image if it is compressed. Returns an error if decompress function is not available.
detectAlpha Returns constant ALPHA_BLEND if the image has data for alpha values. Returns constant ALPHA_BIT if all the alpha values are stored in a single bit. Returns constant ALPHA_NONE if no data for alpha values is found.
expandX2Hq2x Stretches the image and enlarges it by a factor of 2. No interpolation is done.
fill Fills the image with a given Color.
fixAlphaEdges Blends low-alpha pixels with nearby pixels.
flipX Flips the image horizontally.
flipY Flips the image vertically.
generateMipmaps Generates mipmaps for the image. Mipmaps are pre-calculated and lower resolution copies of the image. Mipmaps are automatically used if the image needs to be scaled down when rendered. This improves image quality and the performance of the rendering. Returns an error if the image is compressed, in a custom format or if the image's width/height is 0.
getData Returns the image's raw data.
getFormat Returns the image's format. See format constants.
getHeight Returns the image's height.
getMipmapOffset Returns the offset where the image's mipmap with index mipmap is stored in the data dictionary.
getPixel Returns the color of the pixel at (x, y) if the image is locked. If the image is unlocked, it always returns a Color with the value (0, 0, 0, 1.0). This is the same as getPixelv, but two integer arguments instead of a Vector2 argument.
getPixelv Returns the color of the pixel at src if the image is locked. If the image is unlocked, it always returns a Color with the value (0, 0, 0, 1.0). This is the same as getPixel, but with a Vector2 argument instead of two integer arguments.
getRect Returns a new image that is a copy of the image's area specified with rect.
getSize Returns the image's size (width and height).
getUsedRect Returns a Rect2 enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
getWidth Returns the image's width.
hasMipmaps Returns true if the image has generated mipmaps.
isCompressed Returns true if the image is compressed.
isEmpty Returns true if the image has no data.
isInvisible Returns true if all the image's pixels have an alpha value of 0. Returns false if any pixel has an alpha value higher than 0.
load Loads an image from file path.
loadJpgFromBuffer Loads an image from the binary contents of a JPEG file.
loadPngFromBuffer Loads an image from the binary contents of a PNG file.
loadWebpFromBuffer Loads an image from the binary contents of a WebP file.
lock Locks the data for reading and writing access. Sends an error to the console if the image is not locked when reading or writing a pixel.
normalmapToXy Converts the image's data to represent coordinates on a 3D plane. This is used when the image represents a normalmap. A normalmap can add lots of detail to a 3D surface without increasing the polygon count.
premultiplyAlpha Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256.
resize Resizes the image to the given width and height. New pixels are calculated using interpolation. See interpolation constants.
resizeToPo2 Resizes the image to the nearest power of 2 for the width and height. If square is true then set width and height to be the same.
rgbeToSrgb Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
saveExr Saves the image as an EXR file to path. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return constant ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
savePng Saves the image as a PNG file to path.
setPixel Sets the Color of the pixel at (x, y) if the image is locked. Example:
setPixelv Sets the Color of the pixel at (dst.x, dst.y) if the image is locked. Note that the dst values must be integers. Example:
shrinkX2 Shrinks the image by a factor of 2.
srgbToLinear Converts the raw data from the sRGB colorspace to a linear scale.
unlock Unlocks the data and prevents changes.

Enums

NameDescription
AlphaMode
CompressMode
CompressSource
Constants
Format
Interpolation