zoukankan      html  css  js  c++  java
  • 3dContactPointAnnotationTool开发日志(二)

      今天看的时候发现其实www的方式是可以根据指定路径读取本地图片到Image中的。也就是昨天提到的第二种方式。
      随便选了个图片做示范:
    2.jpg
    1.png
    修改后的代码如下:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class ButtonOkOnClick : MonoBehaviour {
        public InputField imagePath;
        public Image referenceImage;
        
        public void Click() {
            Debug.Log("onClick");
            StartCoroutine(GetImage(imagePath.text));
        }
        private IEnumerator GetImage(string path) {
            Debug.Log(path);
            Debug.Log(path.Replace('\', '/'));
            //WWW www = new WWW("file://"+path.Replace('\','/'));
    
            WWW www = new WWW("file://" + "C:/Users/A/Desktop/2.jpg");
            Debug.Log(www.url);
            yield return www;
            if (www != null && string.IsNullOrEmpty(www.error))
            {
                Texture2D texture = new Texture2D(www.texture.width, www.texture.height);
                texture.SetPixels(www.texture.GetPixels());
                texture.Apply(true);
                texture.filterMode = FilterMode.Trilinear;
                referenceImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            }
            else {
                Debug.Log("no such image!");
            }
        }
    }
    
    
  • 相关阅读:
    厦门大学 ACM 1465 连续数列 三分
    厦门大学 ACM 1437 三分
    南京理工 ACM
    厦门大学 ACM 1466 线段树维护
    LCS N(log (N) )
    hdu 1520
    HDU 2196
    zoj 3710 暴力
    互联网创业盈利模式指南(转)
    map
  • 原文地址:https://www.cnblogs.com/yaoling1997/p/9926307.html
Copyright © 2011-2022 走看看