ImageConversion.EncodeToTGA
Declaration
public static byte[] EncodeToTGA(Texture2D tex);Параметры
| Параметр | Описание |
|---|---|
| Текст | Текстура для кодирования. |
Описание
Кодирует указанную текстуру в формате TGA.
Эта функция возвращает массив байтов, который представляет собой данные файла TGA. Вы можете сохранить кодированные данные в виде файла или отправить их по сети без дальнейшей обработки.
Эта функция не работает на любом сжатом формате. Texture.isReadable должен быть true. Кодированные данные TGA будут несжатыми 8-битными оттенками серого, RGB или RGBA (в зависимости от переданного формата). Для одноканальных красных текстур ( R8, R16, RFloat и RHalf ), кодированные данные TGA будут в 8-битных оттенках серого.
// Saves screenshot as TGA file. using UnityEngine; using System.Collections; using System.IO;
public class TGAScreenSaver : MonoBehaviour { // Take a shot immediately IEnumerator Start() { yield return SaveScreenTGA(); }
IEnumerator SaveScreenTGA() { // Read the screen buffer after rendering is complete yield return new WaitForEndOfFrame();
// Create a texture in RGB24 format the size of the screen int width = Screen.width; int height = Screen.height; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read the screen contents into the texture tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply();
// Encode the texture in TGA format byte[] bytes = ImageConversion.EncodeToTGA(tex); Object.Destroy(tex);
// Write the returned byte array to a file in the project folder File.WriteAllBytes(Application.dataPath + "/../SavedScreen.tga", bytes); } }
Дополнительные ресурсы: ,Texture2D.ReadPixels,, ,WaitForEndOfFrame,, ,LoadImage,, ,EncodeArrayToTGA,, ,EncodeNativeArrayToTGA,, ,EncodeToPNG,, ,EncodeToJPG,, ,EncodeToEXR,.