Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Image
Eredita: Resource < RefCounted < Object
Tipo di dati d'immagine.
Descrizione
Tipo di dati d'immagine nativo. Contiene dati d'immagine che possono essere convertiti in un ImageTexture e fornisce metodi di elaborazione delle immagini di uso comune. La larghezza e l'altezza massime per un Image sono MAX_WIDTH e MAX_HEIGHT.
Un Image non può essere assegnato direttamente a una proprietà texture di un oggetto (come Sprite2D.texture) e deve essere prima convertito manualmente in un ImageTexture.
Nota: I metodi che modificano i dati di un immagine non si possono utilizzare su immagini compresse in VRAM. Usa decompress() per convertire prima l'immagine in un formato non compresso.
Nota: Le dimensioni massime di un'immagine sono 16384×16384 pixel a causa di limitazioni hardware grafiche. Immagini più grandi potrebbero non essere importate.
Tutorial
Proprietà
|
Metodi
void |
adjust_bcs(brightness: float, contrast: float, saturation: float) |
void |
blend_rect(src: Image, src_rect: Rect2i, dst: Vector2i) |
void |
blend_rect_mask(src: Image, mask: Image, src_rect: Rect2i, dst: Vector2i) |
void |
|
void |
blit_rect_mask(src: Image, mask: Image, src_rect: Rect2i, dst: Vector2i) |
void |
bump_map_to_normal_map(bump_scale: float = 1.0) |
void |
|
compress(mode: CompressMode, source: CompressSource = 0, astc_format: ASTCFormat = 0) |
|
compress_from_channels(mode: CompressMode, channels: UsedChannels, astc_format: ASTCFormat = 0) |
|
compute_image_metrics(compared_image: Image, use_luma: bool) |
|
void |
|
void |
|
create(width: int, height: int, use_mipmaps: bool, format: Format) static |
|
create_empty(width: int, height: int, use_mipmaps: bool, format: Format) static |
|
create_from_data(width: int, height: int, use_mipmaps: bool, format: Format, data: PackedByteArray) static |
|
void |
|
detect_alpha() const |
|
detect_used_channels(source: CompressSource = 0) const |
|
void |
|
void |
|
void |
|
void |
flip_x() |
void |
flip_y() |
generate_mipmaps(renormalize: bool = false) |
|
get_data() const |
|
get_data_size() const |
|
get_format() const |
|
get_height() const |
|
get_mipmap_count() const |
|
get_mipmap_offset(mipmap: int) const |
|
get_pixelv(point: Vector2i) const |
|
get_region(region: Rect2i) const |
|
get_size() const |
|
get_used_rect() const |
|
get_width() const |
|
has_mipmaps() const |
|
is_compressed() const |
|
is_empty() const |
|
is_invisible() const |
|
void |
|
load_bmp_from_buffer(buffer: PackedByteArray) |
|
load_dds_from_buffer(buffer: PackedByteArray) |
|
load_exr_from_buffer(buffer: PackedByteArray) |
|
load_from_file(path: String) static |
|
load_jpg_from_buffer(buffer: PackedByteArray) |
|
load_ktx_from_buffer(buffer: PackedByteArray) |
|
load_png_from_buffer(buffer: PackedByteArray) |
|
load_svg_from_buffer(buffer: PackedByteArray, scale: float = 1.0) |
|
load_svg_from_string(svg_str: String, scale: float = 1.0) |
|
load_tga_from_buffer(buffer: PackedByteArray) |
|
load_webp_from_buffer(buffer: PackedByteArray) |
|
void |
|
void |
|
void |
resize(width: int, height: int, interpolation: Interpolation = 1) |
void |
resize_to_po2(square: bool = false, interpolation: Interpolation = 1) |
void |
rotate_90(direction: ClockDirection) |
void |
|
save_dds_to_buffer() const |
|
save_exr(path: String, grayscale: bool = false, color_image: bool = false, max_linear_value: float = -1.0) const |
|
save_exr_to_buffer(grayscale: bool = false, color_image: bool = false, max_linear_value: float = -1.0) const |
|
save_jpg_to_buffer(quality: float = 0.75) const |
|
save_png_to_buffer() const |
|
save_webp(path: String, lossy: bool = false, quality: float = 0.75) const |
|
save_webp_to_buffer(lossy: bool = false, quality: float = 0.75) const |
|
void |
set_data(width: int, height: int, use_mipmaps: bool, format: Format, data: PackedByteArray) |
void |
|
void |
set_pixelv(point: Vector2i, color: Color) |
void |
|
void |
Enumerazioni
enum Format: 🔗
Format FORMAT_L8 = 0
Formato di texture con una singola profondità di 8 bit che rappresenta la luminanza.
Format FORMAT_LA8 = 1
Formato di texture OpenGL con due valori, luminanza e alfa, ciascuno memorizzato con 8 bit.
Format FORMAT_R8 = 2
Formato di texture OpenGL RED con un singolo componente di 8 bit.
Format FORMAT_RG8 = 3
Formato di texture OpenGL RG con due componenti, ciascuno di 8 bit.
Format FORMAT_RGB8 = 4
OpenGL texture format RGB with three components, each with a bitdepth of 8.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_RGBA8 = 5
OpenGL texture format RGBA with four components, each with a bitdepth of 8.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_RGBA4444 = 6
Formato di texture OpenGL RGBA con quattro componenti, ciascuno di 8 bit.
Format FORMAT_RGB565 = 7
Formato di texture OpenGL RGB con tre componenti. Il rosso e il blu sono di 5 bit, e il verde è di 6 bit.
Format FORMAT_RF = 8
Formato di texture OpenGL GL_R32F in cui è presente un solo componente, un valore in virgola mobile di 32 bit.
Format FORMAT_RGF = 9
Formato di texture OpenGL GL_RG32F in cui sono presenti due componenti, ciascuno un valore in virgola mobile di 32 bit.
Format FORMAT_RGBF = 10
Formato di texture OpenGL GL_RGB32F in cui sono presenti tre componenti, ciascuno un valore in virgola mobile di 32 bit.
Format FORMAT_RGBAF = 11
Formato di texture OpenGL GL_RGBA32F in cui sono presenti quattro componenti, ciascuno un valore in virgola mobile di 32 bit.
Format FORMAT_RH = 12
Formato di texture OpenGL GL_R16F in cui è presente un solo componente, un valore in virgola mobile "a mezza precisione" di 16 bit.
Format FORMAT_RGH = 13
Formato di texture OpenGL GL_RG16F in cui sono presenti due componenti, ciascuno un valore in virgola mobile "a mezza precisione" di 16 bit.
Format FORMAT_RGBH = 14
Formato di texture OpenGL GL_RGB16F in cui sono presenti tre componenti, ciascuno un valore in virgola mobile "a mezza precisione" di 16 bit.
Format FORMAT_RGBAH = 15
Formato di texture OpenGL GL_RGBA16F in cui sono presenti quattro componenti, ciascuno un valore in virgola mobile "a mezza precisione" di 16 bit.
Format FORMAT_RGBE9995 = 16
Uno formato speciale di texture OpenGL in cui i tre componenti di colore hanno 9 bit di precisione e tutti e tre condividono un singolo esponente a 5 bit.
Format FORMAT_DXT1 = 17
The S3TC texture format that uses Block Compression 1, and is the smallest variation of S3TC, only providing 1 bit of alpha and color data being premultiplied with alpha.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_DXT3 = 18
The S3TC texture format that uses Block Compression 2, and color data is interpreted as not having been premultiplied by alpha. Well suited for images with sharp alpha transitions between translucent and opaque areas.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_DXT5 = 19
The S3TC texture format also known as Block Compression 3 or BC3 that contains 64 bits of alpha channel data followed by 64 bits of DXT1-encoded color data. Color data is not premultiplied by alpha, same as DXT3. DXT5 generally produces superior results for transparent gradients compared to DXT3.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_RGTC_R = 20
Formato di texture che utilizza la Compressione di texture rosso-verde, normalizzando i dati del canale rosso attraverso lo stesso algoritmo di compressione che DXT5 utilizza per il canale alfa.
Format FORMAT_RGTC_RG = 21
Formato di texture che utilizza la Compressione di texture rosso-verde, normalizzando i dati del canale rosso e verde attraverso lo stesso algoritmo di compressione che DXT5 utilizza per il canale alfa.
Format FORMAT_BPTC_RGBA = 22
Texture format that uses BPTC compression with unsigned normalized RGBA components.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_BPTC_RGBF = 23
Formato di texture che utilizza la compressione BPTC con valori in virgola mobile con segno per i componenti RGB.
Format FORMAT_BPTC_RGBFU = 24
Formato di texture che utilizza la compressione BPTC con valori in virgola mobile senza segno per i componenti RGB.
Format FORMAT_ETC = 25
Formato di compressione di texture Ericsson 1, noto anche come "ETC1", e fa parte dello standard grafico OpenGL ES. Questo formato non può memorizzare un canale alfa.
Format FORMAT_ETC2_R11 = 26
Formato di compressione di texture Ericsson 2 (variante R11_EAC), che fornisce un solo canale di dati senza segno.
Format FORMAT_ETC2_R11S = 27
Formato di compressione di texture Ericsson 2 (variante SIGNED_R11_EAC), che fornisce un solo canale di dati con segno.
Format FORMAT_ETC2_RG11 = 28
Formato di compressione di texture Ericsson 2 (variante RG11_EAC), che fornisce un due canali di dati senza segno.
Format FORMAT_ETC2_RG11S = 29
Formato di compressione di texture Ericsson 2 (variante SIGNED_RG11_EAC), che fornisce un due canali di dati con segno.
Format FORMAT_ETC2_RGB8 = 30
Ericsson Texture Compression format 2 (RGB8 variant), which is a follow-up of ETC1 and compresses RGB888 data.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_ETC2_RGBA8 = 31
Ericsson Texture Compression format 2 (RGBA8variant), which compresses RGBA8888 data with full alpha support.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_ETC2_RGB8A1 = 32
Ericsson Texture Compression format 2 (RGB8_PUNCHTHROUGH_ALPHA1 variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
Note: When creating an ImageTexture, a nonlinear sRGB to linear encoding conversion is performed.
Format FORMAT_ETC2_RA_AS_RG = 33
Formato di compressione di texture Ericsson 2 (variante RGBA8), che comprime i dati RA e li interpreta come due canali (rosso e verde). Vedi anche FORMAT_ETC2_RGBA8.
Format FORMAT_DXT5_RA_AS_RG = 34
Il formato di texture S3TC, noto anche come Block Compression 3 o BC3, che comprime i dati RA e li interpreta come due canali (rosso e verde). Vedi anche FORMAT_DXT5.
Format FORMAT_ASTC_4x4 = 35
Compressione adattiva scalabile di texture. Ciò implementa la modalità 4×4 (alta qualità).
Format FORMAT_ASTC_4x4_HDR = 36
Stesso formato di FORMAT_ASTC_4x4, ma fa sapere alla GPU che viene utilizzato per l'HDR.
Format FORMAT_ASTC_8x8 = 37
Adaptive Scalable Texture Compression. Ciò implementa la modalità 8×8 (bassa qualità).
Format FORMAT_ASTC_8x8_HDR = 38
Stesso formato di FORMAT_ASTC_8x8, ma fa sapere alla GPU che viene utilizzato per l'HDR.
Format FORMAT_R16 = 39
OpenGL texture format GL_R16 where there's one component, a 16-bit unsigned normalized integer value. Since the value is normalized, each component is clamped between 0.0 and 1.0 (inclusive).
Note: Due to limited hardware support, it is mainly recommended to be used on desktop or console devices. It may be unsupported on mobile or web, and will consequently be converted to FORMAT_RF.
Format FORMAT_RG16 = 40
OpenGL texture format GL_RG16 where there are two components, each a 16-bit unsigned normalized integer value. Since the value is normalized, each component is clamped between 0.0 and 1.0 (inclusive).
Note: Due to limited hardware support, it is mainly recommended to be used on desktop or console devices. It may be unsupported on mobile or web, and will consequently be converted to FORMAT_RGF.
Format FORMAT_RGB16 = 41
OpenGL texture format GL_RGB16 where there are three components, each a 16-bit unsigned normalized integer value. Since the value is normalized, each component is clamped between 0.0 and 1.0 (inclusive).
Note: Due to limited hardware support, it is mainly recommended to be used on desktop or console devices. It may be unsupported on mobile or web, and will consequently be converted to FORMAT_RGBF.
Format FORMAT_RGBA16 = 42
OpenGL texture format GL_RGBA16 where there are four components, each a 16-bit unsigned normalized integer value. Since the value is normalized, each component is clamped between 0.0 and 1.0 (inclusive).
Note: Due to limited hardware support, it is mainly recommended to be used on desktop or console devices. It may be unsupported on mobile or web, and will consequently be converted to FORMAT_RGBAF.
Format FORMAT_R16I = 43
OpenGL texture format GL_R16UI where there's one component, a 16-bit unsigned integer value. Each component is clamped between 0 and 65535 (inclusive).
Note: When used in a shader, the texture requires usage of usampler samplers. Additionally, it only supports nearest-neighbor filtering under the Compatibility renderer.
Note: When sampling using get_pixel(), returned Colors have to be divided by 65535 to get the correct color value.
Format FORMAT_RG16I = 44
OpenGL texture format GL_RG16UI where there are two components, each a 16-bit unsigned integer value. Each component is clamped between 0 and 65535 (inclusive).
Note: When used in a shader, the texture requires usage of usampler samplers. Additionally, it only supports nearest-neighbor filtering under the Compatibility renderer.
Note: When sampling using get_pixel(), returned Colors have to be divided by 65535 to get the correct color value.
Format FORMAT_RGB16I = 45
OpenGL texture format GL_RGB16UI where there are three components, each a 16-bit unsigned integer value. Each component is clamped between 0 and 65535 (inclusive).
Note: When used in a shader, the texture requires usage of usampler samplers. Additionally, it only supports nearest-neighbor filtering under the Compatibility renderer.
Note: When sampling using get_pixel(), returned Colors have to be divided by 65535 to get the correct color value.
Format FORMAT_RGBA16I = 46
OpenGL texture format GL_RGBA16UI where there are four components, each a 16-bit unsigned integer value. Each component is clamped between 0 and 65535 (inclusive).
Note: When used in a shader, the texture requires usage of usampler samplers. Additionally, it only supports nearest-neighbor filtering under the Compatibility renderer.
Note: When sampling using get_pixel(), returned Colors have to be divided by 65535 to get the correct color value.
Format FORMAT_MAX = 47
Rappresenta la dimensione dell'enumerazione Format.
enum Interpolation: 🔗
Interpolation INTERPOLATE_NEAREST = 0
Effettua l'interpolazione più vicino. Se l'immagine è ridimensionata, sarà pixelata.
Interpolation INTERPOLATE_BILINEAR = 1
Effettua l'interpolazione bilineare. Se l'immagine è ridimensionata, sarà sfocata. Questa modalità è più veloce di INTERPOLATE_CUBIC, ma produce risultati inferiori.
Interpolation INTERPOLATE_CUBIC = 2
Effettua l'interpolazione cubica. Se l'immagine è ridimensionata, sarà sfocata. Questa modalità spesso produce risultati migliori rispetto a INTERPOLATE_BILINEAR, ma è più lenta.
Interpolation INTERPOLATE_TRILINEAR = 3
Effettua separatamente l'interpolazione bilineare sui due livelli mipmap più adatti, quindi interpola linearmente tra di essi.
È più lento di INTERPOLATE_BILINEAR, ma produce risultati di qualità superiore con molti meno artefatti di aliasing.
Se l'immagine non ha mipmap, queste saranno generate e utilizzate internamente, ma nessuna mipmap sarà generata sull'immagine risultante.
Nota: Se si intende ridimensionare più copie dell'immagine originale, è meglio chiamare in anticipo generate_mipmaps()] su di essa, per evitare di sprecare tempo di elaborazione generandole più volte.
D'altra parte, se l'immagine ha già delle mipmap, queste saranno riutilizzate e sarà generato un nuovo set per l'immagine risultante.
Interpolation INTERPOLATE_LANCZOS = 4
Esegue l'interpolazione di Lanczos. Questa è la modalità di ridimensionamento delle immagini più lenta, ma in genere produce i risultati migliori, specialmente quando si rimpiccioliscono le immagini.
enum AlphaMode: 🔗
AlphaMode ALPHA_NONE = 0
Image is fully opaque. It does not store alpha data.
AlphaMode ALPHA_BIT = 1
Image stores either fully opaque or fully transparent pixels. Also known as punchthrough alpha.
AlphaMode ALPHA_BLEND = 2
Image stores alpha data with values varying between 0.0 and 1.0.
enum CompressMode: 🔗
CompressMode COMPRESS_S3TC = 0
Utilizza la compressione S3TC.
CompressMode COMPRESS_ETC = 1
Utilizza la compressione ETC.
CompressMode COMPRESS_ETC2 = 2
Utilizza la compressione ETC2.
CompressMode COMPRESS_BPTC = 3
Utilizza la compressione BPTC.
CompressMode COMPRESS_ASTC = 4
Utilizza la compressione ASTC.
CompressMode COMPRESS_MAX = 5
Rappresenta la dimensione dell'enumerazione CompressMode.
enum UsedChannels: 🔗
UsedChannels USED_CHANNELS_L = 0
L'immagine utilizza un solo canale per la luminanza (scala di grigi).
UsedChannels USED_CHANNELS_LA = 1
L'immagine utilizza due canali rispettivamente per la luminanza e per l'alfa.
UsedChannels USED_CHANNELS_R = 2
L'immagine utilizza solo il canale rosso.
UsedChannels USED_CHANNELS_RG = 3
L'immagine utilizza due canali per il rosso e il verde.
UsedChannels USED_CHANNELS_RGB = 4
L'immagine utilizza tre canali per il rosso, il verde e il blu.
UsedChannels USED_CHANNELS_RGBA = 5
L'immagine utilizza quattro canali per il rosso, il verde, il blu e l'alfa.
enum CompressSource: 🔗
CompressSource COMPRESS_SOURCE_GENERIC = 0
La texture d'origine (prima della compressione) è una texture regolare. Predefinito per tutte le texture.
CompressSource COMPRESS_SOURCE_SRGB = 1
Source texture (before compression) uses nonlinear sRGB encoding.
CompressSource COMPRESS_SOURCE_NORMAL = 2
La texture d'origine (prima della compressione) è una texture normale (ad esempio può essere compressa in due canali).
enum ASTCFormat: 🔗
ASTCFormat ASTC_FORMAT_4x4 = 0
Suggerimento per indicare che è necessario utilizzare il formato di compressione ASTC 4×4 ad alta qualità.
ASTCFormat ASTC_FORMAT_8x8 = 1
Suggerimento per indicare che è necessario utilizzare il formato di compressione ASTC 8×8 a bassa qualità.
Costanti
MAX_WIDTH = 16777216 🔗
La larghezza massima consentita per le risorse Image.
MAX_HEIGHT = 16777216 🔗
L'altezza massima consentita per le risorse Image.
Descrizioni delle proprietà
Dictionary data = { "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 } 🔗
Contiene tutti i dati di colore dell'immagine in un formato specificato. Vedi le costanti di Format.
Descrizioni dei metodi
void adjust_bcs(brightness: float, contrast: float, saturation: float) 🔗
Regola i parametri di luminosità (brightness), contrasto (contrast) e saturazione (saturation) di questa immagine in base ai valori specificati. Non funziona se l'immagine è compressa (vedi is_compressed()).
void blend_rect(src: Image, src_rect: Rect2i, dst: Vector2i) 🔗
Fonde (con alpha) la regione src_rect dell'immagine src a questa immagine alle coordinate dst, ritagliata adeguatamente a entrambi i limiti dell'immagine. Questa immagine e l'immagine src devono avere lo stesso formato. src_rect con dimensioni non positive è trattata come vuota.
void blend_rect_mask(src: Image, mask: Image, src_rect: Rect2i, dst: Vector2i) 🔗
Fonde con alfa la regione src_rect dall'immagine src a questa immagine usando la immagine maschera mask alle coordinate dst, ritagliate in base a entrambi i limiti delle immagini. I canali alfa sono necessari sia per src sia per mask. I pixel di dst e src si fonderanno se il valore alfa del pixel della maschera corrispondente non è 0. Questa immagine e l'immagine src devono avere lo stesso formato. L'immagine src e l'immagine maschera mask devono avere le stesse dimensioni (larghezza e altezza) ma possono avere formati diversi. src_rect con dimensioni non positive viene trattato come vuoto.
void blit_rect(src: Image, src_rect: Rect2i, dst: Vector2i) 🔗
Copia la regione src_rect dall'immagine src a questa immagine alle coordinate dst, ritagliata in base a entrambi i limiti delle immagini. Questa immagine e l'immagine src devono avere lo stesso formato. src_rect con dimensioni non positive viene trattato come vuoto.
Nota: I dati del canale alfa in src sovrascriveranno i dati corrispondenti in questa immagine nella posizione di destinazione. Per fondere i canali alfa, usa invece blend_rect().
void blit_rect_mask(src: Image, mask: Image, src_rect: Rect2i, dst: Vector2i) 🔗
Blits la regione src_rect dall'immagine src a questa immagine alle coordinate fornite da dst, ritagliata in base a entrambi i limiti dell'immagine. Il pixel src viene copiato su dst se il valore alfa del pixel nella maschera mask corrispondente non è 0. Questa immagine e l'immagine src devono avere lo stesso formato. L'immagine src e l'immagine maschera mask devono avere le stesse dimensioni (larghezza e altezza) ma possono avere formati diversi. src_rect con dimensioni non positive viene trattato come vuoto.
void bump_map_to_normal_map(bump_scale: float = 1.0) 🔗
Converte una mappa di rilievo in una mappa normale. Una mappa di rilievo fornisce un offset di altezza per pixel, mentre una mappa normale fornisce una direzione normale per pixel.
void clear_mipmaps() 🔗
Rimuove i mipmap dell'immagine.
Error compress(mode: CompressMode, source: CompressSource = 0, astc_format: ASTCFormat = 0) 🔗
Comprime l'immagine per usare meno memoria. Non è possibile accedere direttamente ai dati dei pixel mentre l'immagine è compressa. Restituisce un errore se la modalità di compressione scelta non è disponibile.
Il parametro source aiuta a scegliere il metodo di compressione migliore per i formati DXT ed ETC2. È ignorato per la compressione ASTC.
Il parametro astc_format viene considerato solo quando si utilizza la compressione ASTC; è ignorato per tutti gli altri formati.
Nota: compress() è supportato solo nelle build dell'editor. Quando è eseguito in un progetto esportato, questo metodo restituisce sempre @GlobalScope.ERR_UNAVAILABLE.
Error compress_from_channels(mode: CompressMode, channels: UsedChannels, astc_format: ASTCFormat = 0) 🔗
Comprime l'immagine per usare meno memoria. Non è possibile accedere direttamente ai dati pixel mentre l'immagine è compressa. Restituisce un errore se la modalità di compressione scelta non è disponibile.
Questa è un'alternativa a compress() che consente all'utente di fornire i canali utilizzati affinché il compressore scelga i migliori formati DXT ed ETC2. Per altri formati (non DXT o ETC2), questo argomento è ignorato.
Il parametro astc_format viene considerato solo quando si utilizza la compressione ASTC; è ignorato per tutti gli altri formati.
Nota: compress_from_channels() è supportato solo nelle build dell'editor. Quando è eseguito in un progetto esportato, questo metodo restituisce sempre @GlobalScope.ERR_UNAVAILABLE.
Dictionary compute_image_metrics(compared_image: Image, use_luma: bool) 🔗
Compute image metrics on the current image and the compared image. This can be used to calculate the similarity between two images.
The dictionary contains max, mean, mean_squared, root_mean_squared and peak_snr.
void convert(format: Format) 🔗
Converte il formato di questa immagine al formato format.
Copia l'immagine src in questa immagine.
Image create(width: int, height: int, use_mipmaps: bool, format: Format) static 🔗
Deprecato: Use create_empty().
Creates an empty image of the given size and format. If use_mipmaps is true, generates mipmaps for this image (see generate_mipmaps()).
Image create_empty(width: int, height: int, use_mipmaps: bool, format: Format) static 🔗
Creates an empty image of the given size and format. If use_mipmaps is true, generates mipmaps for this image (see generate_mipmaps()).
Image create_from_data(width: int, height: int, use_mipmaps: bool, format: Format, data: PackedByteArray) static 🔗
Crea una nuova immagine di dimensioni e formato specificati. Riempie l'immagine con i dati grezzi specificati. Se use_mipmaps è true, genera i mipmap per questa immagine da data. Vedi generate_mipmaps().
void crop(width: int, height: int) 🔗
Ritaglia l'immagine in base ai parametri width e height. Se le dimensioni specificate sono maggiori delle dimensioni attuali, l'area aggiuntiva viene riempita con pixel neri.
Decomprime l'immagine se è compressa in VRAM in un formato supportato. Ciò aumenta l'utilizzo della memoria, ma consente di modificare l'immagine. Restituisce @GlobalScope.OK se il formato è supportato, altrimenti @GlobalScope.ERR_UNAVAILABLE. È possibile decomprimere tutti i formati compressi in VRAM supportati da Godot con questo metodo, tranne FORMAT_ETC2_R11S, FORMAT_ETC2_RG11S e FORMAT_ETC2_RGB8A1.
AlphaMode detect_alpha() const 🔗
Restituisce ALPHA_BLEND se l'immagine ha dati per i valori alfa. Restituisce ALPHA_BIT se tutti i valori alfa sono memorizzati in un singolo bit. Restituisce ALPHA_NONE se non sono trovati dati per i valori alfa.
UsedChannels detect_used_channels(source: CompressSource = 0) const 🔗
Restituisce i canali colore utilizzati da questa immagine. Se l'immagine è compressa, la sorgente originale (source) deve essere specificata.
Riempie l'immagine con il colore color.
void fill_rect(rect: Rect2i, color: Color) 🔗
Riempe il rettangolo rect con il colore color.
void fix_alpha_edges() 🔗
Fonde i pixel a bassa opacità con i pixel vicini.
void flip_x() 🔗
Capovolge l'immagine orizzontalmente.
void flip_y() 🔗
Capovolge l'immagine verticalmente.
Error generate_mipmaps(renormalize: bool = false) 🔗
Genera mipmap per l'immagine. Le mipmap sono copie precalcolate a bassa risoluzione dell'immagine che sono utilizzate automaticamente se l'immagine deve essere ridotta durante il rendering. Contribuiscono a migliorare la qualità dell'immagine e le prestazioni durante il rendering. Questo metodo restituisce un errore se l'immagine è compressa, in un formato personalizzato, o se la larghezza o l'altezza dell'immagine è 0. Abilitando renormalize durante la generazione delle mipmap per le texture di mappe normali, tutti i valori vettoriali risultanti saranno normalizzati.
È possibile verificare se l'immagine ha mipmap chiamando has_mipmaps() o get_mipmap_count(). Chiamando generate_mipmaps() su un'immagine che ha già mipmap, le mipmap esistenti nell'immagine saranno sostituite.
PackedByteArray get_data() const 🔗
Restituisce una copia dei dati grezzi dell'immagine.
Restituisce la dimensione (in byte) dei dati grezzi dell'immagine.
Restituisce il formato di questa immagine.
Restituisce l'altezza dell'immagine.
int get_mipmap_count() const 🔗
Restituisce il numero di livelli mipmap o 0 se l'immagine non ha mipmap. L'immagine di livello principale più grande non conta come livello mipmap da questo metodo, quindi se vuoi includerla puoi aggiungere 1 a questo conteggio.
int get_mipmap_offset(mipmap: int) const 🔗
Restituisce l'offset in cui il mipmap dell'immagine con indice mipmap è memorizzato nel dizionario data.
Color get_pixel(x: int, y: int) const 🔗
Restituisce il colore del pixel in (x, y).
È lo stesso di get_pixelv(), ma con due argomenti interi invece di un argomento Vector2i.
Color get_pixelv(point: Vector2i) const 🔗
Restituisce il colore del pixel nella posizione point.
È uguale a get_pixel(), ma con un argomento Vector2i invece di due argomenti interi.
Image get_region(region: Rect2i) const 🔗
Restituisce una nuova Image che è una copia dell'area di questa Image specificata con la regione region.
Restituisce le dimensioni dell'immagine (larghezza e altezza).
Rect2i get_used_rect() const 🔗
Restituisce un Rect2i che racchiude la porzione visibile dell'immagine, considerando ogni pixel con un canale alfa diverso da zero come visibile.
Restituisce la larghezza dell'immagine.
Restituisce true se l'immagine ha generato mipmap.
Restituisce true se l'immagine è compressa.
Restituisce true se l'immagine non contiene dati.
Restituisce true se tutti i pixel dell'immagine hanno un valore alfa pari a 0. Restituisce false se un pixel qualsiasi ha un valore alfa superiore a 0.
void linear_to_srgb() 🔗
Converts the entire image from linear encoding to nonlinear sRGB encoding by using a lookup table. Only works on images with FORMAT_RGB8 or FORMAT_RGBA8 formats.
Carica un'immagine dal file al percorso path. Consulta Formati immagine supportati per un elenco dei formati immagine supportati e delle limitazioni.
Attenzione: Questo metodo dovrebbe essere utilizzato solo nell'editor o nei casi in cui è necessario caricare immagini esterne in fase di esecuzione, come immagini situate nella cartella user://, e potrebbe non funzionare nei progetti esportati.
Consulta anche la descrizione di ImageTexture per esempi d'uso.
Error load_bmp_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file BMP.
Nota: Il modulo BMP di Godot non supporta immagini a 16 bit per pixel. Sono supportate solo immagini a 1 bit, 4 bit, 8 bit, 24 bit e 32 bit per pixel.
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo BMP abilitato. Per impostazione predefinita, il modulo BMP è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_bmp_enabled=no.
Error load_dds_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file DDS.
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo DDS abilitato. Per impostazione predefinita, il modulo DDS è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_dds_enabled=no.
Error load_exr_from_buffer(buffer: PackedByteArray) 🔗
Loads an image from the binary contents of an OpenEXR file.
Image load_from_file(path: String) static 🔗
Crea una nuova Image e carica i dati dal file specificato.
Error load_jpg_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file JPEG.
Error load_ktx_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file KTX. A differenza della maggior parte dei formati immagine, KTX può memorizzare dati compressi in VRAM e incorporare mipmap.
Nota: L'implementazione libktx di Godot supporta solo immagini 2D. Cubemap, array di texture e rimozione del padding non sono supportati.
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo KTX abilitato. Per impostazione predefinita, il modulo KTX è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_ktx_enabled=no.
Error load_png_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file PNG.
Error load_svg_from_buffer(buffer: PackedByteArray, scale: float = 1.0) 🔗
Carica un'immagine dal contenuto binario UTF-8 di un file SVG non compresso (.svg).
Nota: Fai attenzione quando usi file SVG compressi (come .svgz), devono essere decompressi prima di essere caricati.
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo SVG abilitato. Per impostazione predefinita, il modulo SVG è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_svg_enabled=no.
Error load_svg_from_string(svg_str: String, scale: float = 1.0) 🔗
Carica un'immagine dal contenuto come stringa di un file SVG (.svg).
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo SVG abilitato. Per impostazione predefinita, il modulo SVG è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_svg_enabled=no.
Error load_tga_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file TGA.
Nota: Questo metodo è disponibile solo nelle build del motore con il modulo TGA abilitato. Per impostazione predefinita, il modulo TGA è abilitato, ma può essere disabilitato in fase di compilazione attraverso l'opzione SCons module_tga_enabled=no.
Error load_webp_from_buffer(buffer: PackedByteArray) 🔗
Carica un'immagine dal contenuto binario di un file WebP.
void normal_map_to_xy() 🔗
Converte i dati dell'immagine per rappresentare coordinate su un piano 3D. È utilizzato quando l'immagine rappresenta una mappa normale. Una mappa normale può aggiungere molti dettagli a una superficie 3D senza aumentare il numero di poligoni.
void premultiply_alpha() 🔗
Moltiplica i valori di colore con i valori alfa. I valori di colore risultanti per un pixel sono (color * alpha)/256. Vedi anche CanvasItemMaterial.blend_mode.
void resize(width: int, height: int, interpolation: Interpolation = 1) 🔗
Resizes the image to the given width and height. New pixels are calculated using the interpolation mode defined via Interpolation constants.
Note: If the image's format is FORMAT_RGBA4444, FORMAT_RGB565, or FORMAT_RGBE9995, it will be temporarily converted to either FORMAT_RGBA8 or FORMAT_RGBAH. This can affect the quality of the resized image.
void resize_to_po2(square: bool = false, interpolation: Interpolation = 1) 🔗
Ridimensiona l'immagine alla potenza di 2 più vicina per larghezza e altezza. Se square è true imposta la larghezza e l'altezza in modo che siano uguali. I nuovi pixel vengono calcolati usando la modalità di interpolazione interpolation.
Converts a standard linear RGBE (Red Green Blue Exponent) image to an image that uses nonlinear sRGB encoding.
void rotate_90(direction: ClockDirection) 🔗
Ruota l'immagine nella direzione specificata da direction di 90 gradi. La larghezza e l'altezza dell'immagine devono essere maggiori di 1. Se la larghezza e l'altezza non sono uguali, l'immagine verrà ridimensionata.
void rotate_180() 🔗
Ruota l'immagine di 180 gradi. La larghezza e l'altezza dell'immagine devono essere maggiori di 1.
Error save_dds(path: String) const 🔗
Salva l'immagine come file DDS (DirectDraw Surface) nel percorso path. DDS è un formato contenitore che può memorizzare texture in vari formati di compressione, come DXT1, DXT5 o BC7. Questa funzione restituirà @GlobalScope.ERR_UNAVAILABLE se Godot è stato compilato senza il modulo DDS.
Nota: Il modulo DDS potrebbe essere disabilitato in certe build, il che significa che save_dds() restituirà @GlobalScope.ERR_UNAVAILABLE quando viene chiamato da un progetto esportato.
PackedByteArray save_dds_to_buffer() const 🔗
Salva l'immagine come file DDS (DirectDraw Surface) in un array di byte. DDS è un formato contenitore che può memorizzare texture in vari formati di compressione, come DXT1, DXT5 o BC7. Questa funzione restituirà @GlobalScope.ERR_UNAVAILABLE se Godot è stato compilato senza il modulo DDS.
Nota: Il modulo DDS potrebbe essere disabilitato in certe build, il che significa che save_dds_to_buffer() restituirà @GlobalScope.ERR_UNAVAILABLE quando viene chiamato da un progetto esportato.
Error save_exr(path: String, grayscale: bool = false, color_image: bool = false, max_linear_value: float = -1.0) const 🔗
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. Set color_image to true when saving a color image, such as a screenshot. Negative values will be included when color_image is false, which may be useful for saving raw floating point data such as a lightmap that includes negative light information. Color component values in the resulting EXR file will not exceed max_linear_value if max_linear_value is not negative. This function will return @GlobalScope.ERR_UNAVAILABLE if Godot was compiled without the TinyEXR module.
When saving screenshots of a project that uses HDR output, use Window.get_output_max_linear_value() for max_linear_value.
PackedByteArray save_exr_to_buffer(grayscale: bool = false, color_image: bool = false, max_linear_value: float = -1.0) const 🔗
Saves the image as an EXR file to a byte array. If grayscale is true and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. Set color_image to true when saving a color image, such as a screenshot. Negative values will be included when color_image is false, which may be useful for saving raw floating point data such as a lightmap that includes negative light information. Color component values in the resulting EXR file will not exceed max_linear_value if max_linear_value is not negative. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
When saving screenshots of a project that uses HDR output, use Window.get_output_max_linear_value() for max_linear_value.
Error save_jpg(path: String, quality: float = 0.75) const 🔗
Salva l'immagine come file JPEG nel percorso path con la qualità quality specificata tra 0.01 e 1.0 (inclusi). Valori di quality più alti producono un aspetto migliore a costo di file più grandi. I valori quality consigliati sono compresi tra 0.75 e 0.90. Anche con una qualità di 1.00, la compressione JPEG rimane lossy.
Nota: JPEG non salva un canale alfa. Se l'Image contiene un canale alfa, l'immagine sarà comunque salvata, ma il file JPEG risultante non conterrà il canale alfa.
PackedByteArray save_jpg_to_buffer(quality: float = 0.75) const 🔗
Salva l'immagine come file JPEG in un array di byte con la qualità quality specificata tra 0.01 e 1.0 (inclusi). Valori di quality più alti producono un aspetto migliore a costo di array di byte più grandi (e quindi più memoria). I valori quality consigliati sono compresi tra 0.75 e 0.90. Anche con una qualità di 1.00, la compressione JPEG rimane lossy.
Nota: JPEG non salva un canale alfa. Se l'Image contiene un canale alfa, l'immagine sarà comunque salvata, ma l'array di byte risultante non conterrà il canale alfa.
Error save_png(path: String) const 🔗
Salva l'immagine come file PNG nel file nel percorso path.
PackedByteArray save_png_to_buffer() const 🔗
Salva l'immagine come file PNG in un array di byte.
Error save_webp(path: String, lossy: bool = false, quality: float = 0.75) const 🔗
Salva l'immagine come file WebP (Web Picture) nel percorso path. Per impostazione predefinita, salva senza perdita di dati. Se lossy è true, l'immagine sarà salvata con perdita di dati, utilizzando la qualità quality tra 0.0 e 1.0 (inclusi). WebP senza perdita offre una compressione più efficiente di PNG.
Nota: Il formato WebP è limitato a una dimensione di 16383×16383 pixel, mentre PNG può salvare immagini più grandi.
PackedByteArray save_webp_to_buffer(lossy: bool = false, quality: float = 0.75) const 🔗
Salva l'immagine come file WebP (Web Picture) in un array di byte. Per impostazione predefinita, salva senza perdita di dati. Se lossy è true, l'immagine sarà salvata con perdita di dati, utilizzando la qualità quality tra 0.0 e 1.0 (inclusi). WebP senza perdita offre una compressione più efficiente di PNG.
Nota: Il formato WebP è limitato a una dimensione di 16383×16383 pixel, mentre PNG può salvare immagini più grandi.
void set_data(width: int, height: int, use_mipmaps: bool, format: Format, data: PackedByteArray) 🔗
Sovrascrive i dati di un'Image esistente. Equivalente non statico di create_from_data().
void set_pixel(x: int, y: int, color: Color) 🔗
Imposta il Color del pixel nelle coordinate (x, y) su color.
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixel(1, 2, Colore.ROSSO) # Imposta il colore in (1, 2) su rosso.
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixel(1, 2, Colori.Rosso); // Imposta il colore in (1, 2) su rosso.
Questo è lo stesso di set_pixelv(), ma con due argomenti interi invece di un argomento Vector2i.
Nota: A seconda del formato dell'immagine, il colore impostato qui potrebbe essere limitato o perdere precisione. Non è garantito che il colore restituito da get_pixel() sia identico a quello impostato qui; qualsiasi confronto richiederà probabilmente l'uso di un'approssimazione come Color.is_equal_approx().
Nota: Nei formati di immagine in scala di grigi, è utilizzato solo il canale rosso di color (e il canale alfa, se pertinente). I canali verde e blu sono ignorati.
void set_pixelv(point: Vector2i, color: Color) 🔗
Imposta il Color del pixel nelle coordinate point su color.
var img_width = 10
var img_height = 5
var img = Image.create(img_width, img_height, false, Image.FORMAT_RGBA8)
img.set_pixelv(Vector2i(1, 2), Color.RED) # Imposta il colore in (1, 2) su rosso.
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Imposta il colore in (1, 2) su rosso.
Questo è lo stesso di set_pixel(), ma con un argomento Vector2i invece di due argomenti interi.
Nota: A seconda del formato dell'immagine, il colore impostato qui potrebbe essere limitato o perdere precisione. Non è garantito che il colore restituito da get_pixel() sia identico a quello impostato qui; qualsiasi confronto richiederà probabilmente l'uso di un'approssimazione come Color.is_equal_approx().
Nota: Nei formati di immagine in scala di grigi, è utilizzato solo il canale rosso di color (e il canale alfa, se pertinente). I canali verde e blu sono ignorati.
void shrink_x2() 🔗
Rimpicciolisce l'immagine di un fattore 2 su ciascun asse (ciò divide il numero di pixel per 4).
void srgb_to_linear() 🔗
Converts the raw data from nonlinear sRGB encoding to linear encoding using a lookup table. Only works on images with FORMAT_RGB8 or FORMAT_RGBA8 formats.
Note: The 8-bit formats required by this method are not suitable for storing linearly encoded values; a significant amount of color information will be lost in darker values. To maintain image quality, this method should not be used.