See the grass and sheep hair pictures, is also really lazy.
Remember to write the weather forecast now forget clean, good memory than rotten pen, or should remember more. I'll shoot you down, okay?
usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;usingUnityengine.ui;usingSystem.IO; Public classreadpictures:monobehaviour{Privateimage Image; Private stringLoadPath ="d:/someother/ngui/assets/streamingassets/test.jpg";//path loaded by IO mode Private stringPicpathwww ="test.jpg";//load mode path of www//Use this for initialization Private voidStart () {image= getcomponent<image>(); //Io method loading speed fast//Loadbyio (); //WWW loading speed is slowloadbywww (); } Private voidLoadbyio () {DoubleStartTime = (Double) Time.time; //Create a file streamFileStream FileStream =NewFileStream (LoadPath, FileMode.Open, FileAccess.Read); Filestream.seek (0, Seekorigin.begin); //create a buffer for file length byte[] bytes =New byte[Filestream.length]; //Read FileFileStream.Read (Bytes,0, (int) filestream.length); //release file read LiuFilestream.close (); Filestream.dispose (); FileStream=NULL; //Create Texture intwidth = -; intHeight =372; Texture2d texture2d=Newtexture2d (width, height); Texture2d.loadimage (bytes); Sprite Sprite= Sprite.create (Texture2d,NewRect (0,0, Texture2d.width, texture2d.height),NewVector2 (0.5f,0.5f)); Image.sprite=Sprite; DoubleTime = (Double) Time.time-StartTime; Debug.Log ("io load Time:"+Time ); } Private voidloadbywww () {Startcoroutine (Load ()); } Private stringURL ="file://D:/SOmeOther/NGUI/Assets/StreamingAssets/";//private String url = "Https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1502532130856&di=7135149ed906483861efdfc9770def3b& Imgtype=0&src=http%3a%2f%2fwww.newasp.net%2fattachment%2fsoft%2f2017%2f0811%2f144057_83971519.png "; Of course, you can change the URL of the network image to load the network pictures PrivateIEnumerator Load () {DoubleStartTime = (Double) Time.time; www www=NewWWW (URL + picpathwww);//only URLs can be placed//www www = new www (URL);//can only be placed URL here to change the URL of the network yield returnwww; if(www!=NULL&&string. IsNullOrEmpty (Www.error)) {texture2d Texture=www.texture; //Create a SpriteSprite Sprite = sprite.create (texture,NewRect (0,0, Texture.width,texture.height),NewVector2 (0.5f,0.5f) ); Image.sprite=Sprite; DoubleTime = (Double) Time.time-StartTime; Debug.Log ("www load time:"+Time ); } }}
Loading pictures in Unity two