zoukankan      html  css  js  c++  java
  • Unity3D图片的下载及保存

    Unity3D图片的下载及保存
    分类: Unity3D 2013-06-24 15:03 3609人阅读 评论(2) 收藏 举报
    Unity3D图片URL
    
    
    
    代码如下:
    
    [csharp] view plaincopy
     using UnityEngine;  
    using System.Collections;  
    using System.IO;  
      
    public class DownPicture : MonoBehaviour {  
      
        public GameObject plane;  
        WWW www;  
        string filePath;  
        Texture2D test;  
        Texture2D newTexture;  
        // Use this for initialization  
        void Start () {  
              
            filePath = Application.dataPath + "/Resources/picture.jpg";  
              
            if (System.IO.File.Exists(filePath))  
            {  
                Debug.Log("文件已存在");  
                test = (Texture2D)Resources.Load("picture", typeof(Texture2D));  
                plane.renderer.material.mainTexture = test;  
            }  
            else  
            {  
                Debug.Log("文件开始下载");  
                StartCoroutine(GetImage());  
                  
            }  
              
        }  
          
        // Update is called once per frame  
        void Update ()   
        {  
              
        }  
      
        IEnumerator GetImage()  
        {  
            string url = "http://192.168.2.105:8080/Test/picture/1.jpg";  
             
            www = new WWW(url);  
            yield return www;  
            newTexture = www.texture;  
              
            byte[] pngData = newTexture.EncodeToPNG();  
            File.WriteAllBytes(filePath, pngData);  
             
        }  
      
        void OnGUI()  
        {  
             
            if (www.isDone)  
                {  
                    plane.renderer.material.mainTexture = newTexture;  
      
                }  
        }  
    }  
    
  • 相关阅读:
    VIM 文本对象选择
    XLA优化实例
    TVM/Relay 的 PartitionGraph()(mod) 函数讨论整理
    OpenCL通用异构开放环境
    LLVM IR 理解
    vue——请求跨域时,vcli2/vcli3设置代理
    【转】SQL 21天实战练习
    bash命令
    linux命令
    jenkins技术
  • 原文地址:https://www.cnblogs.com/ADaii/p/4218434.html
Copyright © 2011-2022 走看看