返回介绍

WWW.LoadImageIntoTexture 加载图像到纹理

发布于 2019-12-18 15:38:47 字数 4261 浏览 1409 评论 0 收藏 0

JavaScript => LoadImageIntoTexture(tex: Texture2D): void;
C# => void LoadImageIntoTexture(Texture2D tex);

Description 描述

Replaces the contents of an existing Texture2D with an image from the downloaded data.

利用一个从下载数据中的图像来替换现有Texture2D。

The data must be an image in JPG or PNG format. If the data is not a valid image, the generated texture will be a small image of a question mark. It is recommended to use power-of-two size for each dimension of the image; arbitrary sizes will also work but can load slightly slower and take up a bit more memory.

这些数据必须是jpg或者png格式的图像,如果数据不是有效的图像,所生成的纹理将是一个问号小图像,这推荐使用的每个图像的大小应该是2的n次幂大小;任何大小尺寸的图像也能被进行加载,但是载入速度会稍微慢些并且占用的内存将会更多。

For PNG files, gamma correction is applied to the texture if PNG file contains gamma information. Display gamma for correction is assumed to be 2.0. If file does not contain gamma information, no color correction will be performed.

对于PNG文件,伽玛校正应用到纹理如果PNG文件包含伽玛信息。伽玛校正显示被假定为2.0。如果文件不包含伽玛信息,没有色彩校正将被执行。

This function replaces texture contents with downloaded image data, so texture size and format might change. JPG files are loaded into RGB24 format, PNG files are loaded into ARGB32 format. If texture format before calling LoadImage is DXT1 or DXT5, then the loaded image will be DXT-compressed (into DXT1 for JPG images and DXT5 for PNG images).

这个函数用下载图像数据替换纹理内容,所以纹理的大小和格式可能会改变结构的内容。 JPG文件加载为RGB24格式,PNG文件加载为ARGB32格式。如果在调用之前纹理格式的加载图像是DXT1或DXT5,那么加载的图像将被DXT压缩(DXT1为JPG图像和DXT5为PNG图像)。

If the data has not finished downloading the texture will be left untouched. Use isDone or yield to see if the data is available.

如果该图片数据还没有被下载完毕,所对应对象的纹理将保持不变,可以使用isDone或者yield去查看数据是否可用。

JavaScript:

// Continuously get the latest webcam shot from outside "Friday's" in Times Square
// and DXT compress them at runtime
var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
 
function Start () { 
	// Create a texture in DXT1 format 
	renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false); 
	while(true) { 
		// Start a download of the given URL 
		var www = new WWW(url);
 
	// wait until the download is done 
		yield www;
 
	// assign the downloaded image to the main texture of the object 
		www.LoadImageIntoTexture(renderer.material.mainTexture); 
	} 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
 
	string url = "http://game.ceeger.com/forum/attachment/background/17be1ac175a9f7c.png";
	IEnumerator Start () {
 
		// Continuously get the latest webcam shot from outside "Friday's" in Times Square
		// and DXT compress them at runtime
 
 
		// Create a texture in DXT1 format 
		renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false); 
		while(true) { 
			// Start a download of the given URL
			WWW www = new WWW(url);
 
			// wait until the download is done 
			yield return www;
 
			// assign the downloaded image to the main texture of the object 
			www.LoadImageIntoTexture(renderer.material.mainTexture as Texture2D); 
		}  
	}
}

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

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

发布评论

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