Image

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 is 16384 pixels.

@GodotBaseClass
struct Image {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

AlphaMode
enum AlphaMode
CompressMode
enum CompressMode
CompressSource
enum CompressSource
Constants
enum Constants
Format
enum Format
Interpolation
enum Interpolation

Functions

_getData
Dictionary _getData()
_setData
void _setData(Dictionary data)
blendRect
void blendRect(Image src, Rect2 src_rect, Vector2 dst)

Alpha-blends src_rect from src image to this image at coordinates dest.

blendRectMask
void blendRectMask(Image src, Image mask, Rect2 src_rect, Vector2 dst)

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
void blitRect(Image src, Rect2 src_rect, Vector2 dst)

Copies src_rect from src image to this image at coordinates dst.

blitRectMask
void blitRectMask(Image src, Image mask, Rect2 src_rect, Vector2 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.

bumpmapToNormalmap
void bumpmapToNormalmap(double bump_scale)
clearMipmaps
void clearMipmaps()

Removes the image's mipmaps.

compress
GodotError compress(long mode, long source, double lossy_quality)

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 COMPRESS_* constants.

convert
void convert(long format)

Converts the image's format. See FORMAT_* constants.

copyFrom
void copyFrom(Image src)

Copies src image to this image.

create
void create(long width, long height, bool use_mipmaps, long format)

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 method.

createFromData
void createFromData(long width, long height, bool use_mipmaps, long format, PoolByteArray data)

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 generate_mipmaps method.

crop
void crop(long width, long height)

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
GodotError decompress()

Decompresses the image if it is compressed. Returns an error if decompress function is not available.

detectAlpha
Image.AlphaMode detectAlpha()

Returns ALPHA_BLEND if the image has data for alpha values. Returns ALPHA_BIT if all the alpha values are below a certain threshold or the maximum value. Returns ALPHA_NONE if no data for alpha values is found.

expandX2Hq2x
void expandX2Hq2x()

Stretches the image and enlarges it by a factor of 2. No interpolation is done.

fill
void fill(Color color)

Fills the image with a given Color.

fixAlphaEdges
void fixAlphaEdges()

Blends low-alpha pixels with nearby pixels.

flipX
void flipX()

Flips the image horizontally.

flipY
void flipY()

Flips the image vertically.

generateMipmaps
GodotError generateMipmaps(bool renormalize)

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
PoolByteArray getData()

Returns the image's raw data.

getFormat
Image.Format getFormat()

Returns the image’s format. See FORMAT_* constants.

getHeight
long getHeight()

Returns the image's height.

getMipmapOffset
long getMipmapOffset(long mipmap)

Returns the offset where the image's mipmap with index mipmap is stored in the data dictionary.

getPixel
Color getPixel(long x, long y)

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).

getPixelv
Color getPixelv(Vector2 src)
getRect
Ref!Image getRect(Rect2 rect)

Returns a new image that is a copy of the image's area specified with rect.

getSize
Vector2 getSize()

Returns the image's size (width and height).

getUsedRect
Rect2 getUsedRect()

Returns a Rect2 enclosing the visible portion of the image.

getWidth
long getWidth()

Returns the image's width.

hasMipmaps
bool hasMipmaps()

Returns true if the image has generated mipmaps.

isCompressed
bool isCompressed()

Returns true if the image is compressed.

isEmpty
bool isEmpty()

Returns true if the image has no data.

isInvisible
bool 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
GodotError load(StringArg0 path)

Loads an image from file path.

loadJpgFromBuffer
GodotError loadJpgFromBuffer(PoolByteArray buffer)

Loads an image from the binary contents of a JPEG file.

loadPngFromBuffer
GodotError loadPngFromBuffer(PoolByteArray buffer)

Loads an image from the binary contents of a PNG file.

loadWebpFromBuffer
GodotError loadWebpFromBuffer(PoolByteArray buffer)

Loads an image from the binary contents of a WebP file.

lock
void lock()

Locks the data for writing access.

normalmapToXy
void 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.

opAssign
Image opAssign(T n)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Image other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(typeof(null) n)
Undocumented in source. Be warned that the author may not have intended to support it.
premultiplyAlpha
void premultiplyAlpha()

Multiplies color values with alpha values. Resulting color values for a pixel are (color * alpha)/256.

resize
void resize(long width, long height, long interpolation)

Resizes the image to the given width and height. New pixels are calculated using interpolation. See interpolation constants.

resizeToPo2
void resizeToPo2(bool square)

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
Ref!Image rgbeToSrgb()
savePng
GodotError savePng(StringArg0 path)

Saves the image as a PNG file to path.

setPixel
void setPixel(long x, long y, Color color)

Sets the Color of the pixel at (x, y) if the image is locked. Example:

setPixelv
void setPixelv(Vector2 dst, Color color)
shrinkX2
void shrinkX2()

Shrinks the image by a factor of 2.

srgbToLinear
void srgbToLinear()

Converts the raw data from the sRGB colorspace to a linear scale.

unlock
void unlock()

Unlocks the data and prevents changes.

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

data
Dictionary data [@property getter]
Dictionary data [@property setter]

Holds all of the image's color data in a given format. See FORMAT_* constants.

Static functions

_new
Image _new()
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

_classBinding
struct _classBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
ToRef as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta