Inherits: Resource < Reference < Object
Image datatype.
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 MAX_WIDTH and MAX_HEIGHT.
Note: The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images will fail to import.
Dictionary | data | {"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0} |
enum Format:
RED
with a single component and a bitdepth of 8.RG
with two components and a bitdepth of 8 for each.RGB
with three components, each with a bitdepth of 8.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
RGBA
with four components, each with a bitdepth of 8.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
RGBA
with four components, each with a bitdepth of 4.GL_RGB5_A1
where 5 bits of depth for each component of RGB and one bit for alpha.GL_R32F
where there's one component, a 32-bit floating-point value.GL_RG32F
where there are two components, each a 32-bit floating-point values.GL_RGB32F
where there are three components, each a 32-bit floating-point values.GL_RGBA32F
where there are four components, each a 32-bit floating-point values.GL_R32F
where there's one component, a 16-bit "half-precision" floating-point value.GL_RG32F
where there are two components, each a 16-bit "half-precision" floating-point value.GL_RGB32F
where there are three components, each a 16-bit "half-precision" floating-point value.GL_RGBA32F
where there are four components, each a 16-bit "half-precision" floating-point value.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
R11_EAC
variant), which provides one channel of unsigned data.SIGNED_R11_EAC
variant), which provides one channel of signed data.RG11_EAC
variant), which provides two channels of unsigned data.SIGNED_RG11_EAC
variant), which provides two channels of signed data.RGB8
variant), which is a follow-up of ETC1 and compresses RGB888 data.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
RGBA8
variant), which compresses RGBA8888 data with full alpha support.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
RGB8_PUNCHTHROUGH_ALPHA1
variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.Note: When creating an ImageTexture, an sRGB to linear color space conversion is performed.
enum Interpolation:
It's slower than INTERPOLATE_BILINEAR, but produces higher-quality results with much less aliasing artifacts.
If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image.
Note: If you intend to scale multiple copies of the original image, it's better to call generate_mipmaps] on it in advance, to avoid wasting processing power in generating them again and again.
On the other hand, if the image already has mipmaps, they will be used, and a new set will be generated for the resulting image.
enum AlphaMode:
enum CompressMode:
enum CompressSource:
Image
resources.Image
resources.Default | {"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0} |
Holds all of the image's color data in a given format. See Format constants.
Alpha-blends src_rect
from src
image to this image at coordinates dest
.
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.
Copies src_rect
from src
image to this image at coordinates dst
.
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.
Converts a bumpmap to a normalmap. A bumpmap provides a height offset per-pixel, while a normalmap provides a normal direction per pixel.
Removes the image's mipmaps.
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.
Converts the image's format. See Format constants.
Copies src
image to this image.
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 generate_mipmaps.
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 loads mipmaps for this image from data
. See generate_mipmaps.
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.
Decompresses the image if it is compressed. Returns an error if decompress function is not available.
Returns ALPHA_BLEND if the image has data for alpha values. Returns ALPHA_BIT if all the alpha values are stored in a single bit. Returns ALPHA_NONE if no data for alpha values is found.
Stretches the image and enlarges it by a factor of 2. No interpolation is done.
Fills the image with a given Color.
Blends low-alpha pixels with nearby pixels.
Flips the image horizontally.
Flips the image vertically.
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.
Returns a copy of the image's raw data.
Returns the image's format. See Format constants.
Returns the image's height.
Returns the offset where the image's mipmap with index mipmap
is stored in the data
dictionary.
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 get_pixelv, but two integer arguments instead of a Vector2 argument.
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 get_pixel, but with a Vector2 argument instead of two integer arguments.
Returns a new image that is a copy of the image's area specified with rect
.
Returns the image's size (width and height).
Returns a Rect2 enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
Returns the image's width.
Returns true
if the image has generated mipmaps.
Returns true
if the image is compressed.
Returns true
if the image has no data.
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.
Loads an image from file path
. See Supported image formats for a list of supported image formats and limitations.
Loads an image from the binary contents of a JPEG file.
Loads an image from the binary contents of a PNG file.
Loads an image from the binary contents of a TGA file.
Loads an image from the binary contents of a WebP file.
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.
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.
Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256
.
Resizes the image to the given width
and height
. New pixels are calculated using interpolation
. See interpolation
constants.
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.
Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
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 @GlobalScope.ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
Saves the image as a PNG file to path
.
Sets the Color of the pixel at (x, y)
if the image is locked. Example:
var img = Image.new() img.create(img_width, img_height, false, Image.FORMAT_RGBA8) img.lock() img.set_pixel(x, y, color) # Works img.unlock() img.set_pixel(x, y, color) # Does not have an effect
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:
var img = Image.new() img.create(img_width, img_height, false, Image.FORMAT_RGBA8) img.lock() img.set_pixelv(Vector2(x, y), color) # Works img.unlock() img.set_pixelv(Vector2(x, y), color) # Does not have an effect
Shrinks the image by a factor of 2.
Converts the raw data from the sRGB colorspace to a linear scale.
Unlocks the data and prevents changes.
© 2014–2020 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
https://docs.godotengine.org/en/3.2/classes/class_image.html