Files
godot-docs-l10n/classes/zh_Hans/class_image.rst
Rémi Verschelde c3f2364c10 Sync classref with 4.6 branch
Lots of translations invalidated (fuzzied) as we just synced Weblate.
2025-12-19 16:39:51 +01:00

1999 lines
118 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. _class_Image:
Image
=====
**继承:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
图像数据类型。
.. rst-class:: classref-introduction-group
描述
----
Native image datatype. Contains image data which can be converted to an :ref:`ImageTexture<class_ImageTexture>` and provides commonly used *image processing* methods. The maximum width and height for an **Image** are :ref:`MAX_WIDTH<class_Image_constant_MAX_WIDTH>` and :ref:`MAX_HEIGHT<class_Image_constant_MAX_HEIGHT>`.
An **Image** cannot be assigned to a texture property of an object directly (such as :ref:`Sprite2D.texture<class_Sprite2D_property_texture>`), and has to be converted manually to an :ref:`ImageTexture<class_ImageTexture>` first.
\ **Note:** Methods that modify the image data cannot be used on VRAM-compressed images. Use :ref:`decompress()<class_Image_method_decompress>` to convert the image to an uncompressed format first.
\ **Note:** The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
.. rst-class:: classref-introduction-group
教程
----
- :doc:`导入图像 <../tutorials/assets_pipeline/importing_images>`
- :doc:`运行时文件加载与保存 <../tutorials/io/runtime_file_loading_and_saving>`
.. rst-class:: classref-reftable-group
属性
----
.. table::
:widths: auto
+-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------------+
| :ref:`Dictionary<class_Dictionary>` | :ref:`data<class_Image_property_data>` | ``{ "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 }`` |
+-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`adjust_bcs<class_Image_method_adjust_bcs>`\ (\ brightness\: :ref:`float<class_float>`, contrast\: :ref:`float<class_float>`, saturation\: :ref:`float<class_float>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`blend_rect<class_Image_method_blend_rect>`\ (\ src\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`blend_rect_mask<class_Image_method_blend_rect_mask>`\ (\ src\: :ref:`Image<class_Image>`, mask\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`blit_rect<class_Image_method_blit_rect>`\ (\ src\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`blit_rect_mask<class_Image_method_blit_rect_mask>`\ (\ src\: :ref:`Image<class_Image>`, mask\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`bump_map_to_normal_map<class_Image_method_bump_map_to_normal_map>`\ (\ bump_scale\: :ref:`float<class_float>` = 1.0\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`clear_mipmaps<class_Image_method_clear_mipmaps>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`compress<class_Image_method_compress>`\ (\ mode\: :ref:`CompressMode<enum_Image_CompressMode>`, source\: :ref:`CompressSource<enum_Image_CompressSource>` = 0, astc_format\: :ref:`ASTCFormat<enum_Image_ASTCFormat>` = 0\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`compress_from_channels<class_Image_method_compress_from_channels>`\ (\ mode\: :ref:`CompressMode<enum_Image_CompressMode>`, channels\: :ref:`UsedChannels<enum_Image_UsedChannels>`, astc_format\: :ref:`ASTCFormat<enum_Image_ASTCFormat>` = 0\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Dictionary<class_Dictionary>` | :ref:`compute_image_metrics<class_Image_method_compute_image_metrics>`\ (\ compared_image\: :ref:`Image<class_Image>`, use_luma\: :ref:`bool<class_bool>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`convert<class_Image_method_convert>`\ (\ format\: :ref:`Format<enum_Image_Format>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`copy_from<class_Image_method_copy_from>`\ (\ src\: :ref:`Image<class_Image>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`create<class_Image_method_create>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`\ ) |static| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`create_empty<class_Image_method_create_empty>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`\ ) |static| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`create_from_data<class_Image_method_create_from_data>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |static| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`crop<class_Image_method_crop>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`decompress<class_Image_method_decompress>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`AlphaMode<enum_Image_AlphaMode>` | :ref:`detect_alpha<class_Image_method_detect_alpha>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`UsedChannels<enum_Image_UsedChannels>` | :ref:`detect_used_channels<class_Image_method_detect_used_channels>`\ (\ source\: :ref:`CompressSource<enum_Image_CompressSource>` = 0\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`fill<class_Image_method_fill>`\ (\ color\: :ref:`Color<class_Color>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`fill_rect<class_Image_method_fill_rect>`\ (\ rect\: :ref:`Rect2i<class_Rect2i>`, color\: :ref:`Color<class_Color>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`fix_alpha_edges<class_Image_method_fix_alpha_edges>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`flip_x<class_Image_method_flip_x>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`flip_y<class_Image_method_flip_y>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`\ (\ renormalize\: :ref:`bool<class_bool>` = false\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`get_data<class_Image_method_get_data>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_data_size<class_Image_method_get_data_size>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_Image_method_get_format>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_height<class_Image_method_get_height>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_mipmap_count<class_Image_method_get_mipmap_count>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_mipmap_offset<class_Image_method_get_mipmap_offset>`\ (\ mipmap\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_Color>` | :ref:`get_pixel<class_Image_method_get_pixel>`\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_Color>` | :ref:`get_pixelv<class_Image_method_get_pixelv>`\ (\ point\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`get_region<class_Image_method_get_region>`\ (\ region\: :ref:`Rect2i<class_Rect2i>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2i<class_Vector2i>` | :ref:`get_size<class_Image_method_get_size>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Rect2i<class_Rect2i>` | :ref:`get_used_rect<class_Image_method_get_used_rect>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_width<class_Image_method_get_width>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_mipmaps<class_Image_method_has_mipmaps>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_compressed<class_Image_method_is_compressed>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_empty<class_Image_method_is_empty>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_invisible<class_Image_method_is_invisible>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`linear_to_srgb<class_Image_method_linear_to_srgb>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load<class_Image_method_load>`\ (\ path\: :ref:`String<class_String>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_bmp_from_buffer<class_Image_method_load_bmp_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_dds_from_buffer<class_Image_method_load_dds_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_exr_from_buffer<class_Image_method_load_exr_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`load_from_file<class_Image_method_load_from_file>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_jpg_from_buffer<class_Image_method_load_jpg_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_ktx_from_buffer<class_Image_method_load_ktx_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_png_from_buffer<class_Image_method_load_png_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_svg_from_buffer<class_Image_method_load_svg_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`, scale\: :ref:`float<class_float>` = 1.0\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_svg_from_string<class_Image_method_load_svg_from_string>`\ (\ svg_str\: :ref:`String<class_String>`, scale\: :ref:`float<class_float>` = 1.0\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_tga_from_buffer<class_Image_method_load_tga_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_webp_from_buffer<class_Image_method_load_webp_from_buffer>`\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`normal_map_to_xy<class_Image_method_normal_map_to_xy>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`premultiply_alpha<class_Image_method_premultiply_alpha>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`resize<class_Image_method_resize>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, interpolation\: :ref:`Interpolation<enum_Image_Interpolation>` = 1\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`resize_to_po2<class_Image_method_resize_to_po2>`\ (\ square\: :ref:`bool<class_bool>` = false, interpolation\: :ref:`Interpolation<enum_Image_Interpolation>` = 1\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Image<class_Image>` | :ref:`rgbe_to_srgb<class_Image_method_rgbe_to_srgb>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`rotate_90<class_Image_method_rotate_90>`\ (\ direction\: :ref:`ClockDirection<enum_@GlobalScope_ClockDirection>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`rotate_180<class_Image_method_rotate_180>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_dds<class_Image_method_save_dds>`\ (\ path\: :ref:`String<class_String>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_dds_to_buffer<class_Image_method_save_dds_to_buffer>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_exr<class_Image_method_save_exr>`\ (\ path\: :ref:`String<class_String>`, grayscale\: :ref:`bool<class_bool>` = false\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_exr_to_buffer<class_Image_method_save_exr_to_buffer>`\ (\ grayscale\: :ref:`bool<class_bool>` = false\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_jpg<class_Image_method_save_jpg>`\ (\ path\: :ref:`String<class_String>`, quality\: :ref:`float<class_float>` = 0.75\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_jpg_to_buffer<class_Image_method_save_jpg_to_buffer>`\ (\ quality\: :ref:`float<class_float>` = 0.75\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_png<class_Image_method_save_png>`\ (\ path\: :ref:`String<class_String>`\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_png_to_buffer<class_Image_method_save_png_to_buffer>`\ (\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_webp<class_Image_method_save_webp>`\ (\ path\: :ref:`String<class_String>`, lossy\: :ref:`bool<class_bool>` = false, quality\: :ref:`float<class_float>` = 0.75\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`save_webp_to_buffer<class_Image_method_save_webp_to_buffer>`\ (\ lossy\: :ref:`bool<class_bool>` = false, quality\: :ref:`float<class_float>` = 0.75\ ) |const| |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_data<class_Image_method_set_data>`\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_pixel<class_Image_method_set_pixel>`\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`, color\: :ref:`Color<class_Color>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_pixelv<class_Image_method_set_pixelv>`\ (\ point\: :ref:`Vector2i<class_Vector2i>`, color\: :ref:`Color<class_Color>`\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`shrink_x2<class_Image_method_shrink_x2>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`srgb_to_linear<class_Image_method_srgb_to_linear>`\ (\ ) |
+-----------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
枚举
----
.. _enum_Image_Format:
.. rst-class:: classref-enumeration
enum **Format**: :ref:`🔗<enum_Image_Format>`
.. _class_Image_constant_FORMAT_L8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_L8** = ``0``
纹理格式,具有代表亮度的单一 8 位深度。
.. _class_Image_constant_FORMAT_LA8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_LA8** = ``1``
OpenGL 纹理格式,具有两个值,亮度和 Alpha都以 8 位存储。
.. _class_Image_constant_FORMAT_R8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_R8** = ``2``
OpenGL 纹理格式 ``RED``\ ,具有单个分量和 8 位深度。
.. _class_Image_constant_FORMAT_RG8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RG8** = ``3``
OpenGL 纹理格式 ``RG``\ ,具有两个部分,每个部分的位深度为 8。
.. _class_Image_constant_FORMAT_RGB8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGB8** = ``4``
OpenGL texture format ``RGB`` with three components, each with a bitdepth of 8.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_RGBA8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBA8** = ``5``
OpenGL texture format ``RGBA`` with four components, each with a bitdepth of 8.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_RGBA4444:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBA4444** = ``6``
OpenGL 纹理格式 ``RGBA`` 有四个部分,每个分量部分的位深度为 4。
.. _class_Image_constant_FORMAT_RGB565:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGB565** = ``7``
OpenGL 纹理格式 ``RGB``\ ,具有三个组件。红色和蓝色的位深度为 5绿色的位深度为 6。
.. _class_Image_constant_FORMAT_RF:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RF** = ``8``
OpenGL 纹理格式 ``GL_R32F``\ 其中有一个分量是32 位浮点值。
.. _class_Image_constant_FORMAT_RGF:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGF** = ``9``
OpenGL 纹理格式 ``GL_RG32F`` 这里有两个部分,每个部分是一个 32 位浮点值。
.. _class_Image_constant_FORMAT_RGBF:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBF** = ``10``
OpenGL 纹理格式 ``GL_RGB32F``\ ,其中有三个部分,每个部分都是 32 位浮点值。
.. _class_Image_constant_FORMAT_RGBAF:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBAF** = ``11``
OpenGL 纹理格式 ``GL_RGBA32F``\ ,其中有四个部分,每个部分都是 32 位浮点值。
.. _class_Image_constant_FORMAT_RH:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RH** = ``12``
OpenGL 纹理格式 ``GL_R16F``\ ,其中有一个分量,即 16 位“半精度”浮点值。
.. _class_Image_constant_FORMAT_RGH:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGH** = ``13``
OpenGL 纹理格式 ``GL_RG16F``\ ,其中有两个分量,每个分量都是 16 位“半精度”浮点值。
.. _class_Image_constant_FORMAT_RGBH:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBH** = ``14``
OpenGL 纹理格式 ``GL_RGB16F``\ ,其中有三个分量,每个分量都是 16 位“半精度”浮点值。
.. _class_Image_constant_FORMAT_RGBAH:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBAH** = ``15``
OpenGL 纹理格式 ``GL_RGBA16F``\ ,其中有四个分量,每个都是 16 位“半精度”浮点值。
.. _class_Image_constant_FORMAT_RGBE9995:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGBE9995** = ``16``
一种特殊的 OpenGL 纹理格式,其中三个颜色成分的精度为 9 位,所有三个成分共享一个 5 比特位的指数。
.. _class_Image_constant_FORMAT_DXT1:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_DXT1** = ``17``
The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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 :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_DXT3:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_DXT3** = ``18``
The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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 :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_DXT5:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_DXT5** = ``19``
The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 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 :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_RGTC_R:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGTC_R** = ``20``
使用\ `红绿贴图压缩 <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__\ 的贴图格式,使用与 DXT5 用于 Alpha 通道相同的压缩算法对红色通道数据进行归一化。
.. _class_Image_constant_FORMAT_RGTC_RG:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_RGTC_RG** = ``21``
使用\ `红绿贴图压缩 <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__\ 的贴图格式,使用与 DXT5 用于 Alpha 的压缩算法相同的红绿数据通道。
.. _class_Image_constant_FORMAT_BPTC_RGBA:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBA** = ``22``
Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with unsigned normalized RGBA components.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_BPTC_RGBF:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBF** = ``23``
使用 `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ 压缩和有符号浮点RGB分量的贴图格式.
.. _class_Image_constant_FORMAT_BPTC_RGBFU:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBFU** = ``24``
使用\ `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ 压缩和无符号浮点RGB分量的贴图格式.
.. _class_Image_constant_FORMAT_ETC:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC** = ``25``
`爱立信纹理压缩格式 1 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#ETC1>`__\ 又称“ETC1”是 OpenGL ES 图形标准的一部分。这种格式无法存储 Alpha 通道。
.. _class_Image_constant_FORMAT_ETC2_R11:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11** = ``26``
`ETC2%E5%92%8CEAC]爱立信纹理压缩格式 2 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#[3>`__\ \ ``R11_EAC`` 变体),它提供一个无符号数据通道。
.. _class_Image_constant_FORMAT_ETC2_R11S:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11S** = ``27``
`ETC2%E5%92%8CEAC]爱立信纹理压缩格式 2 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#[3>`__\ \ ``SIGNED_R11_EAC`` 变体),它提供一个有符号数据通道。
.. _class_Image_constant_FORMAT_ETC2_RG11:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11** = ``28``
`ETC2%E5%92%8CEAC]爱立信纹理压缩格式 2 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#[3>`__\ \ ``RG11_EAC`` 变体),它提供一个无符号数据通道。
.. _class_Image_constant_FORMAT_ETC2_RG11S:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11S** = ``29``
`ETC2%E5%92%8CEAC]爱立信纹理压缩格式 2 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#[3>`__\ \ ``SIGNED_RG11_EAC`` 变体),它提供两个有符号数据通道。
.. _class_Image_constant_FORMAT_ETC2_RGB8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8** = ``30``
`Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8`` variant), which is a follow-up of ETC1 and compresses RGB888 data.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_ETC2_RGBA8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGBA8** = ``31``
`Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGBA8``\ variant), which compresses RGBA8888 data with full alpha support.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_ETC2_RGB8A1:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8A1** = ``32``
`Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8_PUNCHTHROUGH_ALPHA1`` variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
\ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, a nonlinear sRGB to linear encoding conversion is performed.
.. _class_Image_constant_FORMAT_ETC2_RA_AS_RG:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RA_AS_RG** = ``33``
`ETC2%E5%92%8CEAC]爱立信纹理压缩格式 2 <https://zh.wikipedia.org/zh-cn/%E7%88%B1%E7%AB%8B%E4%BF%A1%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9#[3>`__\ \ ``RGBA8`` 变体),能够压缩 RA 数据,将其解释为两个通道(红和绿)。另见 :ref:`FORMAT_ETC2_RGBA8<class_Image_constant_FORMAT_ETC2_RGBA8>`\ 。
.. _class_Image_constant_FORMAT_DXT5_RA_AS_RG:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_DXT5_RA_AS_RG** = ``34``
`S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ 纹理格式,也叫 Block Compression 3、BC3。能够压缩 RA 数据并将其解释为两个通道(红和绿)。另见 :ref:`FORMAT_DXT5<class_Image_constant_FORMAT_DXT5>`\ 。
.. _class_Image_constant_FORMAT_ASTC_4x4:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ASTC_4x4** = ``35``
`自适应可伸缩纹理压缩 <https://zh.wikipedia.org/wiki/%E8%87%AA%E9%80%82%E5%BA%94%E5%8F%AF%E4%BC%B8%E7%BC%A9%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9>`__\ 。这实现了 4×4高质量模式。
.. _class_Image_constant_FORMAT_ASTC_4x4_HDR:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ASTC_4x4_HDR** = ``36``
:ref:`FORMAT_ASTC_4x4<class_Image_constant_FORMAT_ASTC_4x4>` 相同的格式,但有提示以让 GPU 知道它用于 HDR。
.. _class_Image_constant_FORMAT_ASTC_8x8:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ASTC_8x8** = ``37``
`自适应可伸缩纹理压缩 <https://zh.wikipedia.org/wiki/%E8%87%AA%E9%80%82%E5%BA%94%E5%8F%AF%E4%BC%B8%E7%BC%A9%E7%BA%B9%E7%90%86%E5%8E%8B%E7%BC%A9>`__\ 。这实现了 8×8低质量模式。
.. _class_Image_constant_FORMAT_ASTC_8x8_HDR:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_ASTC_8x8_HDR** = ``38``
:ref:`FORMAT_ASTC_8x8<class_Image_constant_FORMAT_ASTC_8x8>` 相同的格式,但有提示以让 GPU 知道它用于 HDR。
.. _class_Image_constant_FORMAT_R16:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`FORMAT_RF<class_Image_constant_FORMAT_RF>`.
.. _class_Image_constant_FORMAT_RG16:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`FORMAT_RGF<class_Image_constant_FORMAT_RGF>`.
.. _class_Image_constant_FORMAT_RGB16:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`FORMAT_RGBF<class_Image_constant_FORMAT_RGBF>`.
.. _class_Image_constant_FORMAT_RGBA16:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`FORMAT_RGBAF<class_Image_constant_FORMAT_RGBAF>`.
.. _class_Image_constant_FORMAT_R16I:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`get_pixel()<class_Image_method_get_pixel>`, returned :ref:`Color<class_Color>`\ s have to be divided by ``65535`` to get the correct color value.
.. _class_Image_constant_FORMAT_RG16I:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`get_pixel()<class_Image_method_get_pixel>`, returned :ref:`Color<class_Color>`\ s have to be divided by ``65535`` to get the correct color value.
.. _class_Image_constant_FORMAT_RGB16I:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`get_pixel()<class_Image_method_get_pixel>`, returned :ref:`Color<class_Color>`\ s have to be divided by ``65535`` to get the correct color value.
.. _class_Image_constant_FORMAT_RGBA16I:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_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 :ref:`get_pixel()<class_Image_method_get_pixel>`, returned :ref:`Color<class_Color>`\ s have to be divided by ``65535`` to get the correct color value.
.. _class_Image_constant_FORMAT_MAX:
.. rst-class:: classref-enumeration-constant
:ref:`Format<enum_Image_Format>` **FORMAT_MAX** = ``47``
代表 :ref:`Format<enum_Image_Format>` 枚举的大小。
.. rst-class:: classref-item-separator
----
.. _enum_Image_Interpolation:
.. rst-class:: classref-enumeration
enum **Interpolation**: :ref:`🔗<enum_Image_Interpolation>`
.. _class_Image_constant_INTERPOLATE_NEAREST:
.. rst-class:: classref-enumeration-constant
:ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_NEAREST** = ``0``
执行最近邻插值。如果调整图像大小,它将被像素化。
.. _class_Image_constant_INTERPOLATE_BILINEAR:
.. rst-class:: classref-enumeration-constant
:ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_BILINEAR** = ``1``
执行双线性插值。如果调整图像大小,则图像将模糊。此模式比 :ref:`INTERPOLATE_CUBIC<class_Image_constant_INTERPOLATE_CUBIC>` 更快,但质量较低。
.. _class_Image_constant_INTERPOLATE_CUBIC:
.. rst-class:: classref-enumeration-constant
:ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_CUBIC** = ``2``
执行三次插值。如果调整图像大小,则图像将模糊。与 :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>` 相比,此模式通常会产生更好的结果,但代价是速度较慢。
.. _class_Image_constant_INTERPOLATE_TRILINEAR:
.. rst-class:: classref-enumeration-constant
:ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_TRILINEAR** = ``3``
在两个最适合的多级渐远纹理级别上分别执行双线性采样,然后在采样结果之间进行线性插值。
它比 :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>` 慢,但能产生更高质量的效果,减少锯齿伪影。
如果图像没有多级渐远纹理,它们将被生成并在内部使用,但不会在生成的图像之上生成多级渐远纹理。
\ **注意:**\ 如果你打算缩放原始图像的多个副本,最好事先对其调用 :ref:`generate_mipmaps()<class_Image_method_generate_mipmaps>`\ ,以避免在生成它们时反复浪费处理能力。
另一方面,如果图像已经有了多级渐远纹理,其将被使用,并为生成的图像生成新的一组。
.. _class_Image_constant_INTERPOLATE_LANCZOS:
.. rst-class:: classref-enumeration-constant
:ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_LANCZOS** = ``4``
执行 Lanczos 插值。这是最慢的图像调整大小模式,但通常可以提供最佳效果,尤其是在缩小图像时。
.. rst-class:: classref-item-separator
----
.. _enum_Image_AlphaMode:
.. rst-class:: classref-enumeration
enum **AlphaMode**: :ref:`🔗<enum_Image_AlphaMode>`
.. _class_Image_constant_ALPHA_NONE:
.. rst-class:: classref-enumeration-constant
:ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_NONE** = ``0``
Image is fully opaque. It does not store alpha data.
.. _class_Image_constant_ALPHA_BIT:
.. rst-class:: classref-enumeration-constant
:ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BIT** = ``1``
Image stores either fully opaque or fully transparent pixels. Also known as punchthrough alpha.
.. _class_Image_constant_ALPHA_BLEND:
.. rst-class:: classref-enumeration-constant
:ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BLEND** = ``2``
Image stores alpha data with values varying between ``0.0`` and ``1.0``.
.. rst-class:: classref-item-separator
----
.. _enum_Image_CompressMode:
.. rst-class:: classref-enumeration
enum **CompressMode**: :ref:`🔗<enum_Image_CompressMode>`
.. _class_Image_constant_COMPRESS_S3TC:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_S3TC** = ``0``
使用 S3TC 压缩。
.. _class_Image_constant_COMPRESS_ETC:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC** = ``1``
使用 ETC 压缩。
.. _class_Image_constant_COMPRESS_ETC2:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC2** = ``2``
使用 ETC2 压缩。
.. _class_Image_constant_COMPRESS_BPTC:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_BPTC** = ``3``
使用 BPTC 压缩。
.. _class_Image_constant_COMPRESS_ASTC:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ASTC** = ``4``
使用 ASTC 压缩。
.. _class_Image_constant_COMPRESS_MAX:
.. rst-class:: classref-enumeration-constant
:ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_MAX** = ``5``
代表 :ref:`CompressMode<enum_Image_CompressMode>` 枚举的大小。
.. rst-class:: classref-item-separator
----
.. _enum_Image_UsedChannels:
.. rst-class:: classref-enumeration
enum **UsedChannels**: :ref:`🔗<enum_Image_UsedChannels>`
.. _class_Image_constant_USED_CHANNELS_L:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_L** = ``0``
该图像仅使用一个通道表示亮度(灰度图)。
.. _class_Image_constant_USED_CHANNELS_LA:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_LA** = ``1``
该图像使用两个通道,分别表示亮度和 Alpha。
.. _class_Image_constant_USED_CHANNELS_R:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_R** = ``2``
该图像仅使用红色通道。
.. _class_Image_constant_USED_CHANNELS_RG:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RG** = ``3``
该图像使用红色和绿色两个通道。
.. _class_Image_constant_USED_CHANNELS_RGB:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RGB** = ``4``
该图像使用红、绿、蓝三个通道。
.. _class_Image_constant_USED_CHANNELS_RGBA:
.. rst-class:: classref-enumeration-constant
:ref:`UsedChannels<enum_Image_UsedChannels>` **USED_CHANNELS_RGBA** = ``5``
该图像使用红色、绿色、蓝色和 Alpha 四个通道。
.. rst-class:: classref-item-separator
----
.. _enum_Image_CompressSource:
.. rst-class:: classref-enumeration
enum **CompressSource**: :ref:`🔗<enum_Image_CompressSource>`
.. _class_Image_constant_COMPRESS_SOURCE_GENERIC:
.. rst-class:: classref-enumeration-constant
:ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_GENERIC** = ``0``
原始纹理(在压缩前)是常规纹理。所有纹理的默认值。
.. _class_Image_constant_COMPRESS_SOURCE_SRGB:
.. rst-class:: classref-enumeration-constant
:ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_SRGB** = ``1``
Source texture (before compression) uses nonlinear sRGB encoding.
.. _class_Image_constant_COMPRESS_SOURCE_NORMAL:
.. rst-class:: classref-enumeration-constant
:ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_NORMAL** = ``2``
原始纹理(在压缩前)是法线纹理(例如可以压缩为两个通道)。
.. rst-class:: classref-item-separator
----
.. _enum_Image_ASTCFormat:
.. rst-class:: classref-enumeration
enum **ASTCFormat**: :ref:`🔗<enum_Image_ASTCFormat>`
.. _class_Image_constant_ASTC_FORMAT_4x4:
.. rst-class:: classref-enumeration-constant
:ref:`ASTCFormat<enum_Image_ASTCFormat>` **ASTC_FORMAT_4x4** = ``0``
表示应该使用高质量 4×4 ASTC 压缩格式的提示。
.. _class_Image_constant_ASTC_FORMAT_8x8:
.. rst-class:: classref-enumeration-constant
:ref:`ASTCFormat<enum_Image_ASTCFormat>` **ASTC_FORMAT_8x8** = ``1``
表示应该使用低质量 8×8 ASTC 压缩格式的提示。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
常量
----
.. _class_Image_constant_MAX_WIDTH:
.. rst-class:: classref-constant
**MAX_WIDTH** = ``16777216`` :ref:`🔗<class_Image_constant_MAX_WIDTH>`
**Image** 资源允许的最大宽度。
.. _class_Image_constant_MAX_HEIGHT:
.. rst-class:: classref-constant
**MAX_HEIGHT** = ``16777216`` :ref:`🔗<class_Image_constant_MAX_HEIGHT>`
**Image** 资源允许的最大高度。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
属性说明
--------
.. _class_Image_property_data:
.. rst-class:: classref-property
:ref:`Dictionary<class_Dictionary>` **data** = ``{ "data": PackedByteArray(), "format": "Lum8", "height": 0, "mipmaps": false, "width": 0 }`` :ref:`🔗<class_Image_property_data>`
以给定的格式保存图像的所有颜色数据。参阅 :ref:`Format<enum_Image_Format>` 常量。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法说明
--------
.. _class_Image_method_adjust_bcs:
.. rst-class:: classref-method
|void| **adjust_bcs**\ (\ brightness\: :ref:`float<class_float>`, contrast\: :ref:`float<class_float>`, saturation\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Image_method_adjust_bcs>`
使用 ``brightness`` 调整图像的亮度,使用 ``contrast`` 调整图像的对比度,使用 ``saturation`` 调整图像的饱和度。对压缩图像无效(见 :ref:`is_compressed()<class_Image_method_is_compressed>`\ )。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_blend_rect:
.. rst-class:: classref-method
|void| **blend_rect**\ (\ src\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`🔗<class_Image_method_blend_rect>`
``src`` 图像上的 ``src_rect`` 与该图像的坐标 ``dst`` 处进行 Alpha 混合,将根据两个图像的边界进行裁剪。该图像和 ``src`` 图像\ **必须**\ 具有相同的格式。具有非正大小的 ``src_rect`` 将被视为空。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_blend_rect_mask:
.. rst-class:: classref-method
|void| **blend_rect_mask**\ (\ src\: :ref:`Image<class_Image>`, mask\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`🔗<class_Image_method_blend_rect_mask>`
使用遮罩图 ``mask``\ ,将源图像 ``src`` 中的 ``src_rect`` 区域的图像Alpha 混合到本图像从坐标 ``dst`` 起的区域,会根据两者的图像区域进行裁剪。\ ``src````mask`` 都需要有 Alpha 通道。如果遮罩图 mask 上某个像素的 Alpha 值非 0则相应的 ``dst`` 的像素和 ``src`` 的像素将混合。这张图像和 ``src`` 图像的格式\ **必须**\ 一致。\ ``src`` 图像和 ``mask`` 图像的大小(宽度和高度)\ **必须**\ 相同,格式可以不同。\ ``src_rect`` 的大小如果非正,则会作为空矩形处理。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_blit_rect:
.. rst-class:: classref-method
|void| **blit_rect**\ (\ src\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`🔗<class_Image_method_blit_rect>`
``src`` 图像上的 ``src_rect`` 复制到该图像的坐标 ``dst`` 处,并根据两个图像边界进行裁剪。该图像和 ``src`` 图像的格式\ **必须**\ 相同。非正数大小的 ``src_rect`` 将被视为空矩形。
\ **注意:**\ ``src`` 中的 Alpha 通道数据会覆盖图像目标位置上对应的数据。要对 Alpha 通道进行混合,请改用 :ref:`blend_rect()<class_Image_method_blend_rect>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_blit_rect_mask:
.. rst-class:: classref-method
|void| **blit_rect_mask**\ (\ src\: :ref:`Image<class_Image>`, mask\: :ref:`Image<class_Image>`, src_rect\: :ref:`Rect2i<class_Rect2i>`, dst\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`🔗<class_Image_method_blit_rect_mask>`
将源图像 ``src`` 上的矩形区域 ``src_rect`` 复制到本图像从坐标 ``dst`` 起的区域,会根据两者的图像区域进行裁剪。如果遮罩图 ``mask`` 上某个像素的 Alpha 值非 0就会把 ``src`` 上对应的像素复制到 ``dst`` 上。这张图像和 ``src`` 图像的格式\ **必须**\ 一致。\ ``src`` 图像和 ``mask`` 图像的大小(宽度和高度)\ **必须**\ 相同,格式可以不同。\ ``src_rect`` 的大小如果非正,则会作为空矩形处理。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_bump_map_to_normal_map:
.. rst-class:: classref-method
|void| **bump_map_to_normal_map**\ (\ bump_scale\: :ref:`float<class_float>` = 1.0\ ) :ref:`🔗<class_Image_method_bump_map_to_normal_map>`
将凹凸贴图转换为法线贴图。凹凸贴图提供每个像素的高度偏移,而法线贴图提供每个像素的法线方向。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_clear_mipmaps:
.. rst-class:: classref-method
|void| **clear_mipmaps**\ (\ ) :ref:`🔗<class_Image_method_clear_mipmaps>`
删除图像的多级渐远纹理。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_compress:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **compress**\ (\ mode\: :ref:`CompressMode<enum_Image_CompressMode>`, source\: :ref:`CompressSource<enum_Image_CompressSource>` = 0, astc_format\: :ref:`ASTCFormat<enum_Image_ASTCFormat>` = 0\ ) :ref:`🔗<class_Image_method_compress>`
Compresses the image with a VRAM-compressed format 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.
The ``source`` parameter helps to pick the best compression method for DXT and ETC2 formats. It is ignored for ASTC compression.
The ``astc_format`` parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
\ **Note:** :ref:`compress()<class_Image_method_compress>` is only supported in editor builds. When run in an exported project, this method always returns :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_compress_from_channels:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **compress_from_channels**\ (\ mode\: :ref:`CompressMode<enum_Image_CompressMode>`, channels\: :ref:`UsedChannels<enum_Image_UsedChannels>`, astc_format\: :ref:`ASTCFormat<enum_Image_ASTCFormat>` = 0\ ) :ref:`🔗<class_Image_method_compress_from_channels>`
Compresses the image with a VRAM-compressed format 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.
This is an alternative to :ref:`compress()<class_Image_method_compress>` that lets the user supply the channels used in order for the compressor to pick the best DXT and ETC2 formats. For other formats (non DXT or ETC2), this argument is ignored.
The ``astc_format`` parameter is only taken into account when using ASTC compression; it is ignored for all other formats.
\ **Note:** :ref:`compress_from_channels()<class_Image_method_compress_from_channels>` is only supported in editor builds. When run in an exported project, this method always returns :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_compute_image_metrics:
.. rst-class:: classref-method
:ref:`Dictionary<class_Dictionary>` **compute_image_metrics**\ (\ compared_image\: :ref:`Image<class_Image>`, use_luma\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_Image_method_compute_image_metrics>`
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``.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_convert:
.. rst-class:: classref-method
|void| **convert**\ (\ format\: :ref:`Format<enum_Image_Format>`\ ) :ref:`🔗<class_Image_method_convert>`
将图像格式转换为 ``format``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_copy_from:
.. rst-class:: classref-method
|void| **copy_from**\ (\ src\: :ref:`Image<class_Image>`\ ) :ref:`🔗<class_Image_method_copy_from>`
将源图像 ``src`` 复制到本图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_create:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **create**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`\ ) |static| :ref:`🔗<class_Image_method_create>`
**已弃用:** Use :ref:`create_empty()<class_Image_method_create_empty>`.
Creates an empty image of the given size and format. If ``use_mipmaps`` is ``true``, generates mipmaps for this image (see :ref:`generate_mipmaps()<class_Image_method_generate_mipmaps>`).
.. rst-class:: classref-item-separator
----
.. _class_Image_method_create_empty:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **create_empty**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`\ ) |static| :ref:`🔗<class_Image_method_create_empty>`
Creates an empty image of the given size and format. If ``use_mipmaps`` is ``true``, generates mipmaps for this image (see :ref:`generate_mipmaps()<class_Image_method_generate_mipmaps>`).
.. rst-class:: classref-item-separator
----
.. _class_Image_method_create_from_data:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **create_from_data**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) |static| :ref:`🔗<class_Image_method_create_from_data>`
创建一个给定大小和格式的新图像。用给定的原始数据填充图像。如果 ``use_mipmaps````true``\ ,则从 ``data`` 为该图像加载 Mipmap。见 :ref:`generate_mipmaps()<class_Image_method_generate_mipmaps>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_crop:
.. rst-class:: classref-method
|void| **crop**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Image_method_crop>`
将该图像裁剪成给定的 ``width````height``\ 。如果指定的大小大于当前大小,则额外的区域用黑色像素填充。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_decompress:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **decompress**\ (\ ) :ref:`🔗<class_Image_method_decompress>`
Decompresses the image if it is VRAM-compressed in a supported format. This increases memory utilization, but allows modifying the image. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if the format is supported, otherwise :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`. All VRAM-compressed formats supported by Godot can be decompressed with this method, except :ref:`FORMAT_ETC2_R11S<class_Image_constant_FORMAT_ETC2_R11S>`, :ref:`FORMAT_ETC2_RG11S<class_Image_constant_FORMAT_ETC2_RG11S>`, and :ref:`FORMAT_ETC2_RGB8A1<class_Image_constant_FORMAT_ETC2_RGB8A1>`.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_detect_alpha:
.. rst-class:: classref-method
:ref:`AlphaMode<enum_Image_AlphaMode>` **detect_alpha**\ (\ ) |const| :ref:`🔗<class_Image_method_detect_alpha>`
如果图像有 Alpha 值的数据,则返回 :ref:`ALPHA_BLEND<class_Image_constant_ALPHA_BLEND>`\ 。如果所有的 Alpha 值都存储在一个位上,则返回 :ref:`ALPHA_BIT<class_Image_constant_ALPHA_BIT>`\ 。如果没有找到 Alpha 值的数据,则返回 :ref:`ALPHA_NONE<class_Image_constant_ALPHA_NONE>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_detect_used_channels:
.. rst-class:: classref-method
:ref:`UsedChannels<enum_Image_UsedChannels>` **detect_used_channels**\ (\ source\: :ref:`CompressSource<enum_Image_CompressSource>` = 0\ ) |const| :ref:`🔗<class_Image_method_detect_used_channels>`
返回图像所使用的颜色通道。如果为压缩图像,则必须使用 ``source`` 指定原始图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_fill:
.. rst-class:: classref-method
|void| **fill**\ (\ color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Image_method_fill>`
使用颜色 ``color`` 填充图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_fill_rect:
.. rst-class:: classref-method
|void| **fill_rect**\ (\ rect\: :ref:`Rect2i<class_Rect2i>`, color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Image_method_fill_rect>`
使用颜色 ``color`` 填充矩形 ``rect``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_fix_alpha_edges:
.. rst-class:: classref-method
|void| **fix_alpha_edges**\ (\ ) :ref:`🔗<class_Image_method_fix_alpha_edges>`
将 Alpha 较低的像素与附近像素混合。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_flip_x:
.. rst-class:: classref-method
|void| **flip_x**\ (\ ) :ref:`🔗<class_Image_method_flip_x>`
水平翻转图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_flip_y:
.. rst-class:: classref-method
|void| **flip_y**\ (\ ) :ref:`🔗<class_Image_method_flip_y>`
垂直翻转图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_generate_mipmaps:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **generate_mipmaps**\ (\ renormalize\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_Image_method_generate_mipmaps>`
为图像生成多级渐远纹理Mipmap。多级渐远纹理是预先计算好的图像的低分辨率副本如果图像在渲染时需要按比例缩小则会自动使用这些副本。它们有助于在渲染时提高图像质量和性能。如果图像被压缩或采用自定义格式或图像的宽度或高度为 ``0``\ ,则该方法返回错误。在为法线纹理生成多级渐远纹理时启用 ``renormalize`` 能够确保得到的所有向量值都是归一化的。
调用 :ref:`has_mipmaps()<class_Image_method_has_mipmaps>`:ref:`get_mipmap_count()<class_Image_method_get_mipmap_count>` 能够检查图像是否使用多级渐远纹理。在已拥有多级渐远纹理的图像上调用 :ref:`generate_mipmaps()<class_Image_method_generate_mipmaps>` 将替换该图像中已有的多级渐远纹理。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_data:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **get_data**\ (\ ) |const| :ref:`🔗<class_Image_method_get_data>`
返回图像原始数据的副本。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_data_size:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_data_size**\ (\ ) |const| :ref:`🔗<class_Image_method_get_data_size>`
返回图像原始数据的大小(单位为字节)。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_format:
.. rst-class:: classref-method
:ref:`Format<enum_Image_Format>` **get_format**\ (\ ) |const| :ref:`🔗<class_Image_method_get_format>`
返回图像的格式。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_height:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_height**\ (\ ) |const| :ref:`🔗<class_Image_method_get_height>`
返回图像的高度。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_mipmap_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_mipmap_count**\ (\ ) |const| :ref:`🔗<class_Image_method_get_mipmap_count>`
返回多级渐远纹理级别数;如果该图像没有多级渐远纹理,则返回 0。该方法不会将最大的主要级别图像计为一个多级渐远纹理级别因此如果你想将其包括在内可以在该计数中加 1。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_mipmap_offset:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_mipmap_offset**\ (\ mipmap\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_Image_method_get_mipmap_offset>`
返回存储在图像的 :ref:`data<class_Image_property_data>` 字典中的索引为 ``mipmap`` 的多级渐远纹理的偏移量。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_pixel:
.. rst-class:: classref-method
:ref:`Color<class_Color>` **get_pixel**\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_Image_method_get_pixel>`
返回 ``(x, y)`` 处的像素的颜色。
这与 :ref:`get_pixelv()<class_Image_method_get_pixelv>` 相同,但使用两个整数参数而不是一个 :ref:`Vector2i<class_Vector2i>` 参数。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_pixelv:
.. rst-class:: classref-method
:ref:`Color<class_Color>` **get_pixelv**\ (\ point\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_Image_method_get_pixelv>`
返回 ``point`` 处像素的颜色。
这与 :ref:`get_pixel()<class_Image_method_get_pixel>` 相同,只是用一个 :ref:`Vector2i<class_Vector2i>` 参数代替了两个整数参数。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_region:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **get_region**\ (\ region\: :ref:`Rect2i<class_Rect2i>`\ ) |const| :ref:`🔗<class_Image_method_get_region>`
返回一个新的 **Image**\ ,它是使用 ``region`` 指定的该 **Image** 区域的副本。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_size:
.. rst-class:: classref-method
:ref:`Vector2i<class_Vector2i>` **get_size**\ (\ ) |const| :ref:`🔗<class_Image_method_get_size>`
返回图像的大小(宽度和高度)。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_used_rect:
.. rst-class:: classref-method
:ref:`Rect2i<class_Rect2i>` **get_used_rect**\ (\ ) |const| :ref:`🔗<class_Image_method_get_used_rect>`
返回一个包含该图像可见部分的 :ref:`Rect2i<class_Rect2i>`\ ,将具有非零 alpha 通道的每个像素视为可见。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_get_width:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_width**\ (\ ) |const| :ref:`🔗<class_Image_method_get_width>`
返回图像的宽度。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_has_mipmaps:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_mipmaps**\ (\ ) |const| :ref:`🔗<class_Image_method_has_mipmaps>`
如果图像已经生成多级渐远纹理,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_is_compressed:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_compressed**\ (\ ) |const| :ref:`🔗<class_Image_method_is_compressed>`
如果图像被压缩,返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_is_empty:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_empty**\ (\ ) |const| :ref:`🔗<class_Image_method_is_empty>`
如果图像没有数据,返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_is_invisible:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_invisible**\ (\ ) |const| :ref:`🔗<class_Image_method_is_invisible>`
如果图像中所有像素的 Alpha 都是 0则返回 ``true``\ 。如果有任何像素的 Alpha 高于 0则返回 ``false``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_linear_to_srgb:
.. rst-class:: classref-method
|void| **linear_to_srgb**\ (\ ) :ref:`🔗<class_Image_method_linear_to_srgb>`
Converts the entire image from linear encoding to nonlinear sRGB encoding by using a lookup table. Only works on images with :ref:`FORMAT_RGB8<class_Image_constant_FORMAT_RGB8>` or :ref:`FORMAT_RGBA8<class_Image_constant_FORMAT_RGBA8>` formats.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_Image_method_load>`
从文件 ``path`` 加载图像。有关支持的图像格式的列表和限制,请参阅\ `支持的图像格式 <../tutorials/assets_pipeline/importing_images.html#supported-image-formats>`__\ 。
\ **警告:**\ 该方法只能用于编辑器,或需要在运行时加载外部图像的情况,例如位于 ``user://`` 目录的图像,并且可能不适用于导出的项目。
另见 :ref:`ImageTexture<class_ImageTexture>` 说明,以获取使用示例。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_bmp_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_bmp_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_bmp_from_buffer>`
从 BMP 文件的二进制内容加载图像。
\ **注意:**\ Godot 的 BMP 模块不支持每像素 16 位的图像。仅支持每像素 1 位、4 位、8 位、24 位和 32 位的图像。
\ **注意:**\ 该方法仅在启用了 BMP 模块的引擎版本中可用。默认情况下BMP 模块是启用的,但可以在构建时使用 ``module_bmp_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_dds_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_dds_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_dds_from_buffer>`
从 DDS 文件的二进制内容加载图像。
\ **注意:**\ 该方法仅在启用了 DDS 模块的引擎版本中可用。默认情况下DDS 模块是启用的,但可以在构建时使用 ``module_dds_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_exr_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_exr_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_exr_from_buffer>`
Loads an image from the binary contents of an OpenEXR file.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_from_file:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **load_from_file**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_Image_method_load_from_file>`
创建一个新的 **Image** 并从指定文件加载数据。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_jpg_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_jpg_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_jpg_from_buffer>`
从 JPEG 文件的二进制内容加载图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_ktx_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_ktx_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_ktx_from_buffer>`
`KTX <https://github.com/KhronosGroup/KTX-Software>`__ 文件的二进制内容加载图像。与大多数图像格式不同KTX 可以存储 VRAM 压缩数据并嵌入 mipmap。
\ **注意:**\ Godot 的 libktx 实现仅支持 2D 图像。不支持立方体贴图、纹理数组和去填充。
\ **注意:**\ 该方法仅在启用了 KTX 模块的引擎版本中可用。默认情况下KTX 模块是启用的,但可以在构建时使用 ``module_ktx_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_png_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_png_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_png_from_buffer>`
从 PNG 文件的二进制内容加载图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_svg_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_svg_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`, scale\: :ref:`float<class_float>` = 1.0\ ) :ref:`🔗<class_Image_method_load_svg_from_buffer>`
从\ **未压缩** SVG 文件(\ **.svg**\ )的 UTF-8 二进制内容加载图像。
\ **注意:**\ 使用压缩的 SVG 文件(如 **.svgz**\ )时请注意,在加载之前需要对其进行 ``decompressed``\ 。
\ **注意:**\ 该方法仅在启用了 SVG 模块的引擎版本中可用。默认情况下SVG 模块是启用的,但可以在构建时使用 ``module_svg_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_svg_from_string:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_svg_from_string**\ (\ svg_str\: :ref:`String<class_String>`, scale\: :ref:`float<class_float>` = 1.0\ ) :ref:`🔗<class_Image_method_load_svg_from_string>`
从 SVG 文件(\ **.svg**\ )的字符串内容加载图像。
\ **注意:**\ 该方法仅在启用了 SVG 模块的引擎版本中可用。SVG 模块默认是启用的,但可以在构建时使用 ``module_svg_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_tga_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_tga_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_tga_from_buffer>`
从 TGA 文件的二进制内容加载图像。
\ **注意:**\ 该方法仅在启用了 TGA 模块的引擎版本中可用。默认情况下TGA 模块是启用的,但可以在构建时使用 ``module_tga_enabled=no`` SCons 选项禁用它。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_load_webp_from_buffer:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load_webp_from_buffer**\ (\ buffer\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_load_webp_from_buffer>`
从 WebP 文件的二进制内容加载图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_normal_map_to_xy:
.. rst-class:: classref-method
|void| **normal_map_to_xy**\ (\ ) :ref:`🔗<class_Image_method_normal_map_to_xy>`
转换图像的数据以表示 3D 平面上的坐标。可以在该图像表示法线贴图时使用。法线贴图可以在不增加多边形数量的情况下向 3D 表面添加大量细节。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_premultiply_alpha:
.. rst-class:: classref-method
|void| **premultiply_alpha**\ (\ ) :ref:`🔗<class_Image_method_premultiply_alpha>`
将颜色值与 Alpha 值相乘。像素的最终颜色值为 ``(color * alpha)/256``\ 。另见 :ref:`CanvasItemMaterial.blend_mode<class_CanvasItemMaterial_property_blend_mode>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_resize:
.. rst-class:: classref-method
|void| **resize**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, interpolation\: :ref:`Interpolation<enum_Image_Interpolation>` = 1\ ) :ref:`🔗<class_Image_method_resize>`
将该图像的宽度调整为 ``width``\ 、高度调整为 ``height``\ 。新的像素使用 ``interpolation`` 插值模式计算,插值模式由 :ref:`Interpolation<enum_Image_Interpolation>` 常量定义。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_resize_to_po2:
.. rst-class:: classref-method
|void| **resize_to_po2**\ (\ square\: :ref:`bool<class_bool>` = false, interpolation\: :ref:`Interpolation<enum_Image_Interpolation>` = 1\ ) :ref:`🔗<class_Image_method_resize_to_po2>`
将图像的宽度和高度调整为最接近的 2 的幂。如果 ``square````true``\ ,则将宽度和高度设置为相同。新像素将通过使用 :ref:`Interpolation<enum_Image_Interpolation>` 常量定义的 ``interpolation`` 模式计算。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_rgbe_to_srgb:
.. rst-class:: classref-method
:ref:`Image<class_Image>` **rgbe_to_srgb**\ (\ ) :ref:`🔗<class_Image_method_rgbe_to_srgb>`
Converts a standard linear RGBE (Red Green Blue Exponent) image to an image that uses nonlinear sRGB encoding.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_rotate_90:
.. rst-class:: classref-method
|void| **rotate_90**\ (\ direction\: :ref:`ClockDirection<enum_@GlobalScope_ClockDirection>`\ ) :ref:`🔗<class_Image_method_rotate_90>`
将该图像按照 ``direction`` 指定的方向旋转 ``90`` 度。该图像的宽度和高度必须大于 ``1``\ 。如果宽和高不相等,则会调整图像的大小。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_rotate_180:
.. rst-class:: classref-method
|void| **rotate_180**\ (\ ) :ref:`🔗<class_Image_method_rotate_180>`
将该图像旋转 ``180`` 度。该图像的宽度和高度必须大于 ``1``\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_dds:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **save_dds**\ (\ path\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_Image_method_save_dds>`
将图像以 DDSDirectDraw Surface文件的形式保存至 ``path`` 路径。DDS 是一种能够以 DXT1、DXT5、BC7 等压缩格式存储纹理的容器格式。如果编译 Godot 时未包含 DDS 模块,则该函数返回 :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`\ 。
\ **注意:**\ 某些构建会禁用 DDS 模块,这意味着当 :ref:`save_dds()<class_Image_method_save_dds>` 从导出的项目中被调用时将返回 :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_dds_to_buffer:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **save_dds_to_buffer**\ (\ ) |const| :ref:`🔗<class_Image_method_save_dds_to_buffer>`
将图像以 DDSDirectDraw Surface文件的形式保存为字节数组。DDS 是一种能够以 DXT1、DXT5、BC7 等压缩格式存储纹理的容器格式。如果编译 Godot 时未包含 DDS 模块,则该函数返回空字节数组。
\ **注意:**\ 某些构建会禁用 DDS 模块,这意味着当 :ref:`save_dds_to_buffer()<class_Image_method_save_dds_to_buffer>` 从导出的项目中被调用时将返回一个空字节数组。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_exr:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **save_exr**\ (\ path\: :ref:`String<class_String>`, grayscale\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_Image_method_save_exr>`
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 :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` if Godot was compiled without the TinyEXR module.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_exr_to_buffer:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **save_exr_to_buffer**\ (\ grayscale\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_Image_method_save_exr_to_buffer>`
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. This function will return an empty byte array if Godot was compiled without the TinyEXR module.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_jpg:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **save_jpg**\ (\ path\: :ref:`String<class_String>`, quality\: :ref:`float<class_float>` = 0.75\ ) |const| :ref:`🔗<class_Image_method_save_jpg>`
将该图像作为 JPEG 文件保存到 ``path``\ ,指定的 ``quality`` 介于 ``0.01````1.0``\ (包括)之间。更高的 ``quality`` 值会以更大的文件大小为代价产生更好看的输出。推荐的 ``quality`` 值介于 ``0.75````0.90`` 之间。即使质量为 ``1.00``\ JPEG 压缩仍然是有损的。
\ **注意:**\ JPEG 不保存 alpha 通道。如果该 **Image** 包含 alpha 通道,该图像仍将被保存,但产生的 JPEG 文件将不包含 alpha 通道。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_jpg_to_buffer:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **save_jpg_to_buffer**\ (\ quality\: :ref:`float<class_float>` = 0.75\ ) |const| :ref:`🔗<class_Image_method_save_jpg_to_buffer>`
将该图像作为 JPEG 文件保存到字节数组中,指定的 ``quality`` 介于 ``0.01````1.0``\ (包括)之间。更高的 ``quality`` 值会以更大的字节数组大小(以及因此的内存使用)为代价产生更好看的输出。推荐的 ``quality`` 值介于 ``0.75````0.90`` 之间。即使质量为 ``1.00``\ JPEG 压缩仍然是有损的。
\ **注意:**\ JPEG 不保存 alpha 通道。如果该 **Image** 包含 alpha 通道,该图像仍将被保存,但产生的字节数组将不包含 alpha 通道。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_png:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **save_png**\ (\ path\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_Image_method_save_png>`
将该图像作为 PNG 文件保存到位于 ``path`` 的文件中。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_png_to_buffer:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **save_png_to_buffer**\ (\ ) |const| :ref:`🔗<class_Image_method_save_png_to_buffer>`
将该图像作为 PNG 文件保存到字节数组中。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_webp:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **save_webp**\ (\ path\: :ref:`String<class_String>`, lossy\: :ref:`bool<class_bool>` = false, quality\: :ref:`float<class_float>` = 0.75\ ) |const| :ref:`🔗<class_Image_method_save_webp>`
将该图像作为 WebPWeb 图片)文件保存到 ``path`` 中的文件中。默认情况下,它将无损保存。如果 ``lossy````true``\ ,则该图像将使用介于 ``0.0````1.0``\ (包含)之间的 ``quality`` 设置进行有损保存。无损 WebP 提供比 PNG 更有效的压缩。
\ **注意:**\ WebP 格式的大小限制为 16383×16383 像素,而 PNG 可以保存更大的图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_save_webp_to_buffer:
.. rst-class:: classref-method
:ref:`PackedByteArray<class_PackedByteArray>` **save_webp_to_buffer**\ (\ lossy\: :ref:`bool<class_bool>` = false, quality\: :ref:`float<class_float>` = 0.75\ ) |const| :ref:`🔗<class_Image_method_save_webp_to_buffer>`
将该图像作为 WebPWeb 图片)文件保存到字节数组中。默认情况下,它将无损保存。如果 ``lossy````true``\ ,则该图像将使用介于 ``0.0````1.0``\ (包含)之间的 ``quality`` 设置进行有损保存。无损 WebP 提供比 PNG 更有效的压缩。
\ **注意:**\ WebP 格式的大小限制为 16383×16383 像素,而 PNG 可以保存更大的图像。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_set_data:
.. rst-class:: classref-method
|void| **set_data**\ (\ width\: :ref:`int<class_int>`, height\: :ref:`int<class_int>`, use_mipmaps\: :ref:`bool<class_bool>`, format\: :ref:`Format<enum_Image_Format>`, data\: :ref:`PackedByteArray<class_PackedByteArray>`\ ) :ref:`🔗<class_Image_method_set_data>`
覆盖现有 **Image** 的数据。\ :ref:`create_from_data()<class_Image_method_create_from_data>` 的非静态等价物。
.. rst-class:: classref-item-separator
----
.. _class_Image_method_set_pixel:
.. rst-class:: classref-method
|void| **set_pixel**\ (\ x\: :ref:`int<class_int>`, y\: :ref:`int<class_int>`, color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Image_method_set_pixel>`
Sets the :ref:`Color<class_Color>` of the pixel at ``(x, y)`` to ``color``.
.. tabs::
.. code-tab:: gdscript
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, Color.RED) # Sets the color at (1, 2) to red.
.. code-tab:: csharp
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixel(1, 2, Colors.Red); // Sets the color at (1, 2) to red.
This is the same as :ref:`set_pixelv()<class_Image_method_set_pixelv>`, but with a two integer arguments instead of a :ref:`Vector2i<class_Vector2i>` argument.
\ **Note:** Depending on the image's format, the color set here may be clamped or lose precision. Do not assume the color returned by :ref:`get_pixel()<class_Image_method_get_pixel>` to be identical to the one set here; any comparisons will likely need to use an approximation like :ref:`Color.is_equal_approx()<class_Color_method_is_equal_approx>`.
\ **Note:** On grayscale image formats, only the red channel of ``color`` is used (and alpha if relevant). The green and blue channels are ignored.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_set_pixelv:
.. rst-class:: classref-method
|void| **set_pixelv**\ (\ point\: :ref:`Vector2i<class_Vector2i>`, color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Image_method_set_pixelv>`
Sets the :ref:`Color<class_Color>` of the pixel at ``point`` to ``color``.
.. tabs::
.. code-tab:: gdscript
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) # Sets the color at (1, 2) to red.
.. code-tab:: csharp
int imgWidth = 10;
int imgHeight = 5;
var img = Image.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);
img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Sets the color at (1, 2) to red.
This is the same as :ref:`set_pixel()<class_Image_method_set_pixel>`, but with a :ref:`Vector2i<class_Vector2i>` argument instead of two integer arguments.
\ **Note:** Depending on the image's format, the color set here may be clamped or lose precision. Do not assume the color returned by :ref:`get_pixelv()<class_Image_method_get_pixelv>` to be identical to the one set here; any comparisons will likely need to use an approximation like :ref:`Color.is_equal_approx()<class_Color_method_is_equal_approx>`.
\ **Note:** On grayscale image formats, only the red channel of ``color`` is used (and alpha if relevant). The green and blue channels are ignored.
.. rst-class:: classref-item-separator
----
.. _class_Image_method_shrink_x2:
.. rst-class:: classref-method
|void| **shrink_x2**\ (\ ) :ref:`🔗<class_Image_method_shrink_x2>`
在每个轴上将图像缩小 2 倍(这会将像素数除以 4
.. rst-class:: classref-item-separator
----
.. _class_Image_method_srgb_to_linear:
.. rst-class:: classref-method
|void| **srgb_to_linear**\ (\ ) :ref:`🔗<class_Image_method_srgb_to_linear>`
Converts the raw data from nonlinear sRGB encoding to linear encoding using a lookup table. Only works on images with :ref:`FORMAT_RGB8<class_Image_constant_FORMAT_RGB8>` or :ref:`FORMAT_RGBA8<class_Image_constant_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.
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
.. |void| replace:: :abbr:`void (无返回值。)`