Unity_ picture read local resources (notes - turn)

  We read in the local Unity picture resources, for example, read the summary of three kinds of methods:

1. method using Resource.Load read, read resource name under the Resources directory Unity in Assets, do not pay attention to the use of the suffix. (Meaning the Load method to find the resources directly in the Resources directory, the path has been specified).           
            // Load picture Embodiment 1; (pictures to be placed in the Assets / Resources / directory);
            the Texture2D _tex = (the Texture2D) Resources.Load ( "Lighthouse");

2. the class loader using WWW resources, this class can be loaded WWW network resources (http: // format), the file protocol resources (flie: // format), ftp format and so on.
            // Load picture mode 2; (you can load the network server and the local picture);
            String filePath = "File: //" + @ + Application.dataPath "/ _ Image / grid.png";
            the WWW the WWW = new new the WWW (filePath);
            WWW return the yield;

3. image class using C # loading pictures, picture data acquired image class, filled with Unity Texture2D data. Note that the problem may arise in this way:
         Assets / _Script / AddObjBtnEvent.cs (57,20): error CS0234: The type or namespace name

`Drawing 'does not exist in the namespace` System' Are you missing an assembly reference.?         One solution:
        D: \ Program Files \ Unity \ Editor \ the Data \ Mono \ lib \ Mono \ 2.0 \ System.Drawing.dll System.Drawing.dll dragged under this path to the next level Project panel, you can compile.

            // Load picture mode 3;
            filePath = @ Application.dataPath + "/ _ Image / grid.png";
            the FileStream FS = new new the FileStream (filePath, FileMode.Open, FileAccess.Read);
            System.Drawing.Image the System.Drawing img = .Image.FromStream (FS);
//System.Drawing.Image.FromFile(filePath); // method two load picture mode.
          
            MS = new new the MemoryStream the MemoryStream ();
            img.Save (MS, System.Drawing.Imaging.ImageFormat.Png);

            = New new _tex2 the Texture2D the Texture2D (128, 128);
            _tex2.LoadImage (ms.ToArray ());

            texture type material here // attach GameObject read;
            _newObj.renderer.material.mainTexture = _tex2;

reprinted: http://wuzhouyi2012.blog.163.com/blog/static/204968271201301744231736/

Guess you like

Origin www.cnblogs.com/Roz-001/p/11304605.html