如何统一保存图片到phone内存(androidphone)

how to save the image to the phone memory(android phone) in unity

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Test1 : MonoBehaviour {
public int textureWidth = 400;
public int textureHeight = 400;

public RawImage textureDisplayer;

void Start()
{
    string imageUrl = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
    StartCoroutine(LoadImg(imageUrl));
}

void displayImage(Texture2D imgToDisp)
{
    //Resize Image
    textureDisplayer.GetComponent<RectTransform>().sizeDelta = new Vector2(textureWidth, textureHeight);
    textureDisplayer.texture = imgToDisp;
    byte[] bytes = imgToDisp.EncodeToPNG();
    System.IO.File.WriteAllBytes("image", bytes);
}


IEnumerator LoadImg(string url)
{
    yield return null;
    WWW www = new WWW(url);
    yield return www;

    displayImage(www.texture);
}


}

这里我试图将 impToDisp 保存到我的 phone 内存中。 在我的代码中,我能够加载图像。

我需要将加载的图像保存到我的 phone memory.how 我可以这样做吗

我认为你需要考虑使用 MemoryStream。

例如:

  using (MemoryStream ms = new MemoryStream())
            {
                myBitmap.Save(ms, myBitmap.RawFormat);
            }

在 Unity3d 论坛中查看此示例: http://answers.unity3d.com/questions/563113/saving-png-image-to-memorystream-causes-access-vio.html