unity 加载图片

1.IO加载

 public void GetQRImage(string path)
    {
        using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
        {
            fileStream.Seek(0, SeekOrigin.Begin);
            byte[] bytes = new byte[fileStream.Length];
            fileStream.Read(bytes, 0, (int)fileStream.Length);
            fileStream.Close();
            fileStream.Dispose();
            int _width = 216;
            int _height = 216;//
            Texture2D texture2D = new Texture2D(_width, _height);
            texture2D.LoadImage(bytes);
            Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), povit);
            QR.GetComponent<Image>().sprite = sprite;
            QRmin.GetComponent<Image>().sprite = sprite;
            Debug.Log("IO加载成功:前置图片");
        }

    }

2.WWW加载

 public  IEnumerator ImageTexture(string url,Image image)
    {
        WWW www = new WWW(url);
        Debug.Log(url);
        yield return www;
        Texture2D tex = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGBA32, false);
        tex.wrapMode = TextureWrapMode.Clamp;
        tex = www.texture;
        image.GetComponent<Image>().sprite = Sprite.Create(tex, new Rect(0,0, tex.width, tex.height), Vector2.zero);
      
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值