This article fixed connection: http://blog.csdn.net/u013108312/article/details/52712844
www implementation of picture resource display and save and local loading
Using Unityengine;Using System.Collections;Using System.IO;Using Unityeditor;Enum getpictype{DownLoad =0, Localload,}PublicClass picture:monobehaviour{Here is the local IP addressString url ="Http://127.0.0.1:80000/1.jpg";///<summary>Web-downloaded pictures///</summary>Private texture2d img =Null///<summary>Local pictures///</summary>Private Texture2d Img2 =NullPrivateBOOL Downloadok =Falsevoid Ongui () {if (This.img! =NULL) GUI. Drawtexture (New Rect (0,0,200,300),THIS.IMG);if (This.img2! =NULL) GUI. Drawtexture (New Rect (320,0,200,300),THIS.IMG2);if (GUI. Button (New Rect (210,0,100,20),"Show Network Pictures") {Startcoroutine (This. Downloadtexture (This.url, getpictype.download)); }if (GUI. Button (New Rect (210,40M100,20),"Show local picture") {if (This.downloadok) {Startcoroutine (Downloadtexture ("file://" + Application.streamingassetspath +"/1.png", Getpictype.localload)); }else {Debug.logerror ("No download Completed"); }}} IEnumerator Downloadtexture (String URL, getpictype getType) {www www =New WWW (URL); Texture2d Tempimage;Yieldreturn www;if (www.isDone && www.error = =NULL) {Switch (getType) {Case Getpictype.download: {this.img = www.texture; Tempimage =THIS.IMG; Debug.Log (tempimage.width + "+ Tempimage.height"); break;} case getpictype.localload: this.img2 = www.texture; tempImage = THIS.IMG; Debug.Log (tempimage.width + "+ Tempimage.height"); break; default:tempimage = null; break;} if (tempimage! = null) {byte[] data = Tempimage.encodetopng (); File.writeallbytes (Application.streamingassetspath + "/1.png", data); this.downloadok = true;}} }}
Unity3d-www to display picture resources and save and load locally