0
幫助我們,我正在創建增強現實(unity + vuforia)。我有按鈕屏幕截圖屏幕,是工作,但文件位置(/Data/Data/com.companyname.gamename/Files)。如何更改文件夾? (存儲/模擬/ 0/DCIM /相機/)。問:在Android手機上,如何更改文件夾
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();
}
}
謝謝,它的工作。但畫面並未出現在我的畫廊中,如何讓它出現?圖片格式有問題嗎? (我使用的圖片格式是PNG) –
我認爲這是另一個問題的主題;) –