返回介绍

Texture2D.GetRawTextureData 获取原始纹理数据

发布于 2019-12-18 15:38:39 字数 1865 浏览 1533 评论 0 收藏 0

JavaScript => public function GetRawTextureData(): byte[];
C# => public byte[] GetRawTextureData();

Returns 返回值

byte[] Raw texture data as a byte array.

返回原始纹理的字节组。

Description 描述

Get raw data from a texture.

从纹理获取原始数据。

This function returns the raw texture data as a byte array, which you can then use with Texture2D.LoadRawTextureData. This allows you to serialize and load textures of any format (including compressed ones), and to load them back into a texture later.

该函数返回原始纹理数据的字节组,然后你可以使用Texture2D.LoadRawTextureData,这让你序列化和加载任意格式的纹理(包括压缩的),以及以后加载返回纹理。

JavaScript:

#pragma strict
class CopyTexture extends MonoBehaviour {
	var tex: Texture2D;
	function Start() {
		// Create a copy of the texture by reading and applying the raw texture data.
		var texCopy: var = new Texture2D(tex.width, tex.height, tex.format, tex.mipmapCount > 1);
		texCopy.LoadRawTextureData(tex.GetRawTextureData());
		texCopy.Apply();
	}
}

C#:

using UnityEngine;
 
class CopyTexture: MonoBehaviour
{
	// the source texture.
	Texture2D tex;
 
	void Start()
	{
		// Create a copy of the texture by reading and applying the raw texture data.
		var texCopy = new Texture2D(tex.width, tex.height, tex.format, tex.mipmapCount > 1);
		texCopy.LoadRawTextureData(tex.GetRawTextureData());
		texCopy.Apply ();
	}
}

Texture2D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文