WWW.LoadImageIntoTexture 加载图像到纹理

function LoadImageIntoTexture (tex : Texture2D) : void

Parameters参数

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去查看数据是否可用。

// Continuously get the latest webcam shot from outside "Friday's" in Times Square

//连续获取时代广场最新的外部"Friday"web摄像头数据

// and DXT compress them at runtime

//并且使用DXT实时压缩

var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";



function Start () {

	// Create a texture in DXT1 format

	//创建一个为DXT1的纹理格式

	renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);



	while(true) {

		// Start a download of the given URL

		//开始一个被给定的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); 

	}

}

  if (t_load == null)   

  {        

	  Debug.Log("Application data path: " + Application.dataPath);        

	  string targetFile = "file://" + Application.dataPath + "/Resources/Textures/Icons/Chairs_65x65.png";       

	  Debug.Log("Beginning load at time: " + Time.time);       

	  t_load = new WWW(targetFile);    

  }   

  else if (t_load.isDone && t_dynamic_tx == null)   

  {        

	  Debug.Log("File has finished being loaded at " + Time.time);        

	  t_dynamic_tx = new Texture2D(65, 65);        

	  Debug.Log("Preparing to load PNG into Texture");        

	  t_load.LoadImageIntoTexture(t_dynamic_tx);        

	  Debug.Log("Loaded image into texture");   

  }
Page last updated: 2011-4-25