UnityEngine.Texture2D.LoadImage C# (CSharp) Method

LoadImage() private method

private LoadImage ( byte data ) : bool
data byte
return bool
        public bool LoadImage(byte[] data)
        {
            bool markNonReadable = false;
            return this.LoadImage(data, markNonReadable);
        }

Same methods

Texture2D::LoadImage ( byte data, [ markNonReadable ) : bool

Usage Example

コード例 #1
1
    /*	The only necessary method - follows two step process outlined above
     *	Returns album art as a new texture
     */
    public Texture getAlbumArtAsTexture(GameObject audioHolder, FileInfo f)
    {
        Texture2D albumArt = new Texture2D (1, 1); //empty texture holder

        foreach (Transform file in audioHolder.transform.parent) { //loads all files from current directory - will not result in massive searches because we only pass files until an album container is created
            if (file.gameObject.name.EndsWith(".jpg") || file.gameObject.name.EndsWith(".png")) { //pull album art from images found in directory
                byte[] bytes = System.IO.File.ReadAllBytes(file.gameObject.name); //pull byte stream from image file
                albumArt.LoadImage(bytes); //load byte stream into new texture
                return albumArt;
            }
            else {
                if (file.name != "AlbumTitle") {//scrape album art from music file data
                    TagLib.File tagFile = TagLib.File.Create(file.name);
                    if (tagFile.Tag.Pictures.Length == 0) {
                        return null; //default texture
                    }
                    TagLib.IPicture albumPic = tagFile.Tag.Pictures [0];
                    MemoryStream stream = new MemoryStream (albumPic.Data.Data);
                    byte[] tagBytes;
                    byte[] buffer = new byte[16 * 1024];
                    using (MemoryStream ms = new MemoryStream()) { //read image data into new stream
                        int read;
                        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) {
                            ms.Write(buffer, 0, read);
                        }
                        tagBytes = ms.ToArray();
                    }
                    albumArt.LoadImage (tagBytes); //convert stream data into new texture
                    return albumArt;
                }
            }
        }

        return null;
    }
All Usage Examples Of UnityEngine.Texture2D::LoadImage