美文网首页
图片转码字节数组,字节数组转码图片

图片转码字节数组,字节数组转码图片

作者: 不过一书生 | 来源:发表于2018-04-24 19:08 被阅读0次

    using System.Collections;

    using System.Collections.Generic;

    using System.IO;

    using System.Text;

    using UnityEngine;

    using UnityEngine.UI;

    public class Test : MonoBehaviour

    {

        public RawImage leftImage;

        private string path = "\\Assets\\StreamingAssets\\001.jpg";

        WWW w;

        public byte[] FunTurnTo(string path)

        {

            FileStream fileStream = new FileStream(path, FileMode.Open, System.IO.FileAccess.Read);

            fileStream.Seek(0, SeekOrigin.Begin);

            byte[] buffer = new byte[fileStream.Length];

            fileStream.Read(buffer, 0, (int)fileStream.Length);

            fileStream.Close();

            fileStream.Dispose();

            fileStream = null;

            print(456);

            return buffer;

        }

        public void PicToByteArray()

        {

            byte[] bear =  FunTurnTo(System.Environment.CurrentDirectory + path);

            FileStream fs = new FileStream(System.Environment.CurrentDirectory + "\\Assets\\StreamingAssets\\666.jpg", FileMode.Create, FileAccess.Write);

            fs.Write(bear, 0, bear.Length);

            fs.Close();

            StartCoroutine(LoadPicOfStreamingAssets());

            leftImage.texture = w.texture;

            print(123);

        }

        IEnumerator LoadPicOfStreamingAssets()

        {

            w = new WWW(System.Environment.CurrentDirectory + "\\Assets\\StreamingAssets\\666.jpg");

            return w;

        }

    }

    相关文章

      网友评论

          本文标题:图片转码字节数组,字节数组转码图片

          本文链接:https://www.haomeiwen.com/subject/tfxslftx.html