В: На телефоне Android, как изменить папку

Помогите ребята, я создаю дополненную реальность (unity+vuforia). У меня есть кнопка для снимка экрана, она работает, но файл находится в (/Data/Data/com.companyname.gamename/Files). Как сменить папку? (хранение/эмуляция/0/DCIM/камера/) .

using UnityEngine;
using System.Collections;
using System.IO;
public class SnapshotShare : MonoBehaviour
{
    private AndroidUltimatePluginController androidUltimatePluginController;
    Camera mainCamera;
    RenderTexture renderTex;
    Texture2D screenshot;
    Texture2D LoadScreenshot;
    int width = Screen.width;
    int height = Screen.height;
    string fileName;
    string screenShotName = "Animal3D_";

    void Start ()
    {
        androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();
    }

    public void Snapshot ()
    {
        StartCoroutine (CaptureScreen ());
    }

    public IEnumerator CaptureScreen ()
    {
        yield return null;
        GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false;
        yield return new WaitForEndOfFrame ();
        if (Screen.orientation == ScreenOrientation.Portrait || Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
            mainCamera = Camera.main.GetComponent<Camera> ();
            renderTex = new RenderTexture (height, width, 24);
            mainCamera.targetTexture = renderTex;
            RenderTexture.active = renderTex;
            mainCamera.Render ();
            screenshot = new Texture2D (height, width, TextureFormat.RGB24, false);
            screenshot.ReadPixels (new Rect (0, 0, height, width ), 0, 0);
            screenshot.Apply ();
            RenderTexture.active = null;
            mainCamera.targetTexture = null;
        }
        if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) {
            mainCamera = Camera.main.GetComponent<Camera> ();
            renderTex = new RenderTexture (width, height, 24);
            mainCamera.targetTexture = renderTex;
            RenderTexture.active = renderTex;
            mainCamera.Render ();
            screenshot = new Texture2D (width, height, TextureFormat.RGB24, false);
            screenshot.ReadPixels (new Rect (0, 0, width, height), 0, 0);
            screenshot.Apply (); //false
            RenderTexture.active = null;
            mainCamera.targetTexture = null;
        }
        File.WriteAllBytes (Application.persistentDataPath + "/" +screenShotName+Time.frameCount+".jpg", screenshot.EncodeToJPG ());
        GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = true;
    }

    public void LoadImage ()
    {
        string path = Application.persistentDataPath + "/" + screenShotName;
        byte[] bytes;
        bytes = System.IO.File.ReadAllBytes(path);
        LoadScreenshot = new Texture2D(1,1);
        LoadScreenshot.LoadImage(bytes);
        GameObject.FindGameObjectWithTag ("Picture").GetComponent<Renderer> ().material.mainTexture = screenshot;
    }

    public void close ()
    {
        Application.Quit ();
    }
}

person Stephen Louis    schedule 30.07.2016    source источник


Ответы (1)


Взято из здесь (подробнее) и здесь (обсуждение).

Я предлагаю вам сохранить захваченный снимок экрана в папке приложения (/Data/Data/com.companyname.gamename/Files), а затем использовать File.Move(source, dest), чтобы переместить его:

if(Shot_Taken == true)
{
    string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
    // This is the path of my folder.
    string Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
    if(System.IO.File.Exists(Origin_Path))
    {
        System.IO.File.Move(Origin_Path, Path);
        Shot_Taken = false;
    }
}
person Michael Spitsin    schedule 30.07.2016
comment
Спасибо, это сработало. Но картинка не появляется в моей галерее, как сделать чтобы она появилась? Что-то не так с форматом картинки? (я использовал формат изображения png) - person Stephen Louis; 30.07.2016
comment
Думаю, это тема для другого вопроса ;) - person Michael Spitsin; 31.07.2016