跳转至

Image

继承

Resource

简要描述

图像数据类型。

描述

本机图像数据类型。包含图像数据,可以被转换为一个文理,一些可交互的函数。

成员

类型 属性名 默认值
Dictionary data

方法

返回值类型 方法名称
void blend_rect(src: Image, src_rect: Rect2, dst: Vector2)
void blend_rect_mask(src: Image, mask: Image, src_rect: Rect2, dst: Vector2)
void blit_rect(src: Image, src_rect: Rect2, dst: Vector2)
void blit_rect_mask(src: Image, mask: Image, src_rect: Rect2, dst: Vector2)
void bumpmap_to_normalmap(bump_scale: float = 1.0)
void clear_mipmaps()
int compress(mode: int, source: int, lossy_quality: float)
void convert(format: int)
void copy_from(src: Image)
void create(width: int, height: int, use_mipmaps: bool, format: int)
void create_from_data(width: int, height: int, use_mipmaps: bool, format: int, data: PoolByteArray)
void crop(width: int, height: int)
int decompress()
int detect_alpha() const
void expand_x2_hq2x()
void fill(color: Color)
void fix_alpha_edges()
void flip_x()
void flip_y()
int generate_mipmaps(renormalize: bool = false)
PoolByteArray get_data() const
int get_format() const
int get_height() const
int get_mipmap_offset(mipmap: int) const
Color get_pixel(x: int, y: int) const
Color get_pixelv(src: Vector2) const
Image get_rect(rect: Rect2) const
Vector2 get_size() const
Rect2 get_used_rect() const
int get_width() const
bool has_mipmaps() const
bool is_compressed() const
bool is_empty() const
bool is_invisible() const
int load(path: String)
int load_jpg_from_buffer(buffer: PoolByteArray)
int load_png_from_buffer(buffer: PoolByteArray)
int load_webp_from_buffer(buffer: PoolByteArray)
void lock()
void normalmap_to_xy()
void premultiply_alpha()
void resize(width: int, height: int, interpolation: int = 1)
void resize_to_po2(square: bool = false)
Image rgbe_to_srgb()
int save_exr(path: String, grayscale: bool = false) const
int save_png(path: String) const
void set_pixel(x: int, y: int, color: Color)
void set_pixelv(dst: Vector2, color: Color)
void shrink_x2()
void srgb_to_linear()
void unlock()
##枚举
enum Format:
- FORMAT_L8 = 0

具有表示亮度的单个8位深度的纹理格式。

  • FORMAT_LA8 = 1

OpenGL纹理格式,具有两个值(亮度和alpha值),每个值存储8位。

  • FORMAT_R8 = 2

OpenGL纹理格式RED,具有单个组件,位深度为8。

  • FORMAT_RG8 = 3

OpenGL纹理格式RG,包含两个组件,每个组件的位深度为8。

  • FORMAT_RGB8 = 4

OpenGL纹理格式RGB具有三个组成部分,每个组成部分的位深度为8。

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_RGBA8 = 5

OpenGL纹理格式RGBA具有四个组成部分,每个组成部分的位深度为8。

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_RGBA4444 = 6

OpenGL纹理格式RGBA具有四个组成部分,每个组成部分的位深为4。

  • FORMAT_RGBA5551 = 7

OpenGL纹理格式GL_RGB5_A1,其中RGB的每个分量的深度为5位,而alpha的深度为1位。

  • FORMAT_RF = 8

OpenGL纹理格式GL_R32F,其中包含一个组成部分,即32位浮点值。

  • FORMAT_RGF = 9

OpenGL纹理格式GL_RG32F,其中有两个组件,每个组件都是32位浮点值。

  • FORMAT_RGBF = 10

OpenGL纹理格式GL_RGB32F,其中包含三个组成部分,每个组成部分为32位浮点值。

  • FORMAT_RGBAF = 11

OpenGL纹理格式GL_RGBA32F,其中包含四个组件,每个组件都是32位浮点值。

  • FORMAT_RH = 12

OpenGL纹理格式GL_R32F,其中包含一个组成部分,即16位“半精度”浮点值。

  • FORMAT_RGH = 13

OpenGL纹理格式GL_RG32F,其中有两个组件,每个组件都是16位的“半精度”浮点值。

  • FORMAT_RGBH = 14

OpenGL纹理格式GL_RGB32F,其中包含三个组成部分,每个组成部分均为16位“半精度”浮点值。

  • FORMAT_RGBAH = 15

OpenGL纹理格式GL_RGBA32F,其中包含四个组成部分,每个组成部分均为16位“半精度”浮点值。

  • FORMAT_RGBE9995 = 16

一种特殊的OpenGL纹理格式,其中三个颜色分量具有9位精度,并且所有三个颜色分量共享一个5位指数。

  • FORMAT_DXT1 = 17

[=] S3TC [/url]纹理格式使用块压缩1,并且是S3TC的最小变体,仅提供1​​位的alpha和颜色数据被预乘

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_DXT3 = 18

使用块压缩2的[=] S3TC [/url]纹理格式,并且颜色数据被解释为没有预乘alpha。

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_DXT5 = 19

[=] S3TC [/url]纹理格式也称为块压缩3或BC3,其中包含64位的alpha通道数据,后跟64位的DXT1编码颜色

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_RGTC_R = 20

使用[=]红色绿色纹理压缩[/url]的纹理格式,使用与DXT5用于alpha通道相同的压缩算法对红色通道数据进行归一化。

  • FORMAT_RGTC_RG = 21

使用[=]红色绿色纹理压缩[/url]的纹理格式,使用与DXT5用于alpha的压缩算法相同的红色和绿色通道数据

  • FORMAT_BPTC_RGBA = 22

使用[=] BPTC [/url]压缩和无符号归一化RGBA组件的纹理格式。

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_BPTC_RGBF = 23

使用[=] BPTC [/url]压缩和带符号浮点RGB分量的纹理格式。

  • FORMAT_BPTC_RGBFU = 24

使用[=] BPTC [/url]压缩和无符号浮点RGB分量的纹理格式。

  • FORMAT_PVRTC2 = 25

在PowerVR支持的移动平台上使用的纹理格式使用2位颜色深度,没有alpha。

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_PVRTC2A = 26

与[=] PVRTC2 [/url]相同,但带有alpha成分。

  • FORMAT_PVRTC4 = 27

与[=] PVRTC2 [/url]类似,但具有4位色深且没有Alpha。

  • FORMAT_PVRTC4A = 28

与[=] PVRTC4 [/url]相同,但带有alpha成分。

  • FORMAT_ETC = 29

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

  • FORMAT_ETC2_R11 = 30

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

  • FORMAT_ETC2_R11S = 31

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

  • FORMAT_ETC2_RG11 = 32

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

  • FORMAT_ETC2_RG11S = 33

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

  • FORMAT_ETC2_RGB8 = 34

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_ETC2_RGBA8 = 35

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_ETC2_RGB8A1 = 36

[url = https://en.wikipedia.org/wiki/Ericsson_Texture_Compression

**注意:**创建ImageTexture时,将执行sRGB到线性色彩空间的转换。

  • FORMAT_MAX = 37

表示Format枚举的大小。


enum Interpolation: - INTERPOLATE_NEAREST = 0

执行最近邻插值。

  • INTERPOLATE_BILINEAR = 1

执行双线性插值。

  • INTERPOLATE_CUBIC = 2

执行三次插值。

  • INTERPOLATE_TRILINEAR = 3

在两个最适合的Mipmap级别分别执行双线性,然后在它们之间线性内插。

它比INTERPOLATE_BILINEAR慢,但产生的结果质量更高,而别名失真更少。

如果图像没有mipmap,则将在内部生成和使用它们,但是在生成的图像上将不会生成mipmap。

**注意:**如果要缩放原始图像的多个副本,最好事先对其进行调用generate_mipmaps],以避免在一次又一次地生成它们时浪费处理能力。

另一方面,如果图像已经具有mipmap,则将使用它们,并为生成的图像生成新的一组。

  • INTERPOLATE_LANCZOS = 4

执行Lanczos插值。当downscaling图像时,这是最慢的resizing模式,但是却是结果最好的。


enum AlphaMode: - ALPHA_NONE = 0

图片没有Alpha。

  • ALPHA_BIT = 1

图像仅将alpha存储。

  • ALPHA_BLEND = 2

图片使用Alpha。


enum CompressMode: - COMPRESS_S3TC = 0

使用S3TC压缩。

  • COMPRESS_PVRTC2 = 1

使用PVRTC2压缩。

  • COMPRESS_PVRTC4 = 2

使用PVRTC4压缩。

  • COMPRESS_ETC = 3

使用ETC压缩。

  • COMPRESS_ETC2 = 4

使用ETC2压缩。


enum CompressSource: - COMPRESS_SOURCE_GENERIC = 0

源纹理(压缩前)是常规纹理。

  • COMPRESS_SOURCE_SRGB = 1

源纹理(压缩前)在sRGB空间中。

  • COMPRESS_SOURCE_NORMAL = 2

源纹理(在压缩之前)是正常纹理(例如,可以压缩为两个通道)。


常量

  • MAX_WIDTH = 16384

Image资源允许的最大宽度。

  • MAX_HEIGHT = 16384

Image资源允许的最大高度。

成员说明

  • Dictionary data
Default {"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0}
setter _set_data(value)
getter _get_data

方法说明

  • blend_rect blend_rect(src: Image, src_rect: Rect2, dst: Vector2)

src图像中的src_rect混合到此坐标为dest的图像上。


  • blend_rect_mask blend_rect_mask(src: Image, mask: Image, src_rect: Rect2, dst: Vector2)

使用mask图像在dst坐标处将src图像中的src_rect混合到此图像。Alpha通道被src和mask需要。dst 像素跟src像素会被混合,如果对应的mask像素的alpha值不为0。


  • blit_rect blit_rect(src: Image, src_rect: Rect2, dst: Vector2)

src_rectsrc图像复制到此图像,坐标为dst


  • blit_rect_mask blit_rect_mask(src: Image, mask: Image, src_rect: Rect2, dst: Vector2)

dst给定的坐标处,将src_rect区域从src图像拖到该图像。src像素被拷贝至dst,如果对应的mask像素的alpha值不为0。


  • bumpmap_to_normalmap bumpmap_to_normalmap(bump_scale: float = 1.0)

将凹凸贴图转换为法线贴图。Bumpmap提供高度偏移。


  • clear_mipmaps clear_mipmaps()

删除图像的mipmap。


  • compress compress(mode: int, source: int, lossy_quality: float)

压缩图像以使用更少的内存。当图像被压缩时,不能直接访问像素数据。返回错误如果被选择的压缩模式不可使用。


  • convert convert(format: int)

转换图像的格式。


  • copy_from copy_from(src: Image)

src图片复制到该图片。


  • create create(width: int, height: int, use_mipmaps: bool, format: int)

创建给定大小和格式的空图像。如果use_mipmaps是true,则生成对应的mipmaps。


  • create_from_data create_from_data(width: int, height: int, use_mipmaps: bool, format: int, data: PoolByteArray)

创建给定大小和格式的新图像。填充当前图像使用给定的原始数据,如果use_mipmaps是true,则生成对应的mipmaps。


  • crop crop(width: int, height: int)

将图像裁剪为给定的widthheight。如果指定的大小大于当前大小,则而外的空间会被填充黑色的像素。


  • decompress decompress()

解压缩图像(如果已压缩)。返回一个错误如果解压函数不可用。


  • detect_alpha detect_alpha() const

如果图像具有alpha值的数据,则返回ALPHA_BLEND。返回ALPHA_BIT如果所有的alpha值都被存储在一个单独bit中。


  • expand_x2_hq2x expand_x2_hq2x()

拉伸图像并将其放大2倍。不进行插值。


  • fill fill(color: Color)

用给定的[颜色]填充图像。


  • fix_alpha_edges fix_alpha_edges()

将低alpha像素与附近的像素混合。


  • flip_x flip_x()

水平翻转图像。


  • flip_y flip_y()

垂直翻转图像。


  • generate_mipmaps generate_mipmaps(renormalize: bool = false)

生成图像的mipmap。Mipmaps是预计算的第分辨率的图像的拷贝。Mipmaps是自动被使用的如果图像需要被缩放。者可以提升图像的质量以及渲染的性能。


  • get_data get_data() const

返回图像的原始数据。


  • get_format get_format() const

返回图像的格式。


  • get_height get_height() const

返回图像的高度。


  • get_mipmap_offset get_mipmap_offset(mipmap: int) const

返回索引为mipmap的图像mipmap存储在data字典中的偏移量。


  • get_pixel get_pixel(x: int, y: int) const

如果图像被锁定,则返回(x,y)处像素的颜色。如果图像被解锁,将总是返回(0,0,0,1.0).get_pixel跟此一样。


  • get_pixelv get_pixelv(src: Vector2) const

如果图像被锁定,则返回src处像素的颜色。如果图像被解锁,则总是返回(0,0,0,1.0)。get_pixel跟此一样。


  • get_rect get_rect(rect: Rect2) const

返回一个新图像,该图像是rect指定的图像区域的副本。


  • get_size get_size() const

返回图像的大小(宽度和高度)。


  • get_used_rect get_used_rect() const

返回一个Rect2,其中包含图像的可见部分,并将具有非零alpha通道的每个像素视为可见。


  • get_width get_width() const

返回图像的宽度。


  • has_mipmaps has_mipmaps() const

如果图像已生成mipmap,则返回true


  • is_compressed is_compressed() const

如果图像已压缩,则返回true


  • is_empty is_empty() const

如果图像没有数据,则返回true


  • is_invisible is_invisible() const

如果图像的所有像素的alpha值均为0,则返回true。如果任何像素的alpha值均大于0,则返回false


  • load load(path: String)

从文件path加载图像。


  • load_jpg_from_buffer load_jpg_from_buffer(buffer: PoolByteArray)

从JPEG文件的二进制内容加载图像。


  • load_png_from_buffer load_png_from_buffer(buffer: PoolByteArray)

从PNG文件的二进制内容加载图像。


  • load_webp_from_buffer load_webp_from_buffer(buffer: PoolByteArray)

从WebP文件的二进制内容加载图像。


  • lock lock()

锁定数据以进行读写访问。


  • normalmap_to_xy normalmap_to_xy()

转换图像数据以表示3D平面上的坐标。这在当图像表示normalmap时会被使用。


  • premultiply_alpha premultiply_alpha()
                      将颜色值与alpha值相乘。结果是color * alpha /256。
    

  • resize resize(width: int, height: int, interpolation: int = 1)

将图像调整为给定的widthheight。新的像素被计算使用插值。


  • resize_to_po2 resize_to_po2(square: bool = false)

将图像的宽度和高度调整为最接近的2的幂。如果square 是true则设置宽高一样。


  • rgbe_to_srgb rgbe_to_srgb()

将标准RGBE(红绿蓝指数)图像转换为sRGB图像。


  • save_exr save_exr(path: String, grayscale: bool = false) const

将图像另存为EXR文件到path。如果grascale是true,则会被保存为但色彩值。


  • save_png save_png(path: String) const

将图像另存为PNG文件到path


  • set_pixel set_pixel(x: int, y: int, color: Color)

如果图像被锁定,则将像素的Color设置为(x,y)

var img = Image.new()
img.createimg_widthimg_heightfalseImage.FORMAT_RGBA8
img.lock()
img.set_pixelxycolor
img.unlock()
img.set_pixelxycolor

  • set_pixelv set_pixelv(dst: Vector2, color: Color)

如果图像被锁定,则将像素的Color设置为(dst.x,dst.y)

var img = Image.new()
img.createimg_widthimg_heightfalseImage.FORMAT_RGBA8
img.lock()
img.set_pixelvVector2xy),颜色
img.unlock()
img.set_pixelvVector2xy),颜色

  • shrink_x2 shrink_x2()

将图像缩小2倍。


  • srgb_to_linear srgb_to_linear()

将原始数据从sRGB色彩空间转换为线性比例。


  • unlock unlock()

解锁数据并防止更改。