728x90
[unity] iOS ์จ๋ฒ์ ์ด๋ฏธ์ง ์ ์ฅํ๊ธฐ
1. Asset Store
Native Gallery for Android & iOS import ํ๊ธฐ
์ฐธ์กฐ UnityNativeGallery
2. ์คํฌ๋ฆฝํธ ์์ฑ
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CameraCapture : MonoBehaviour
{
[SerializeField]
private Button TakePhotoButton;
public int fileCounter;
private Camera Camera
{
get
{
if (!_camera)
{
// _camera = Camera.main;
_camera = Camera.main;
}
return _camera;
}
}
[SerializeField]
private Camera _camera;
void Awake()
{
TakePhotoButton.onClick.AddListener(TakePhoto);
}
private void TakePhoto()
{
Debug.Log("TakePhoto()" + fileCounter);
Capture();
}
public void Capture()
{
RenderTexture activeRenderTexture = RenderTexture.active;
RenderTexture.active = Camera.targetTexture;
Camera.Render();
Texture2D image = new Texture2D(Camera.targetTexture.width, Camera.targetTexture.height);
image.ReadPixels(new Rect(0, 0, Camera.targetTexture.width, Camera.targetTexture.height), 0, 0);
image.Apply();
RenderTexture.active = activeRenderTexture;
byte[] bytes = image.EncodeToPNG();
Destroy(image);
// Mac path :
// cf) https://docs.unity3d.com/ScriptReference/Application-dataPath.html?_ga=2.85471643.307249663.1629898360-1836162968.1629898360&_gl=1*1kwusal*_ga*MTgzNjE2Mjk2OC4xNjI5ODk4MzYw*_ga_1S78EFL1W5*MTYyOTkwMDcyMi4yLjAuMTYyOTkwMDcyMi42MA..
// File.WriteAllBytes(Application.dataPath + "/Image/" + fileCounter + ".png", bytes);
// cf2) https://devparklibrary.tistory.com/32
// Debug.Log(Application.persistentDataPath);
// File.WriteAllBytes(Application.persistentDataPath +"/Image" +fileCounter + ".png", bytes);
// iOS Mobile
string name = "AR Camera" + System.DateTime.Now.ToString("yyyy-mm-dd_HH-mm-ss") +fileCounter + ".png";
NativeGallery.SaveImageToGallery(bytes, "AR Camera Assistant picutres", name);
fileCounter++;
}
}
NativeGallery.SaveImageToGallery(bytes, "AR Camera Assistant picutres", name)๋ก ios14 ์ด์์ ๋ฒ์ ์์ ์จ๋ฒ์ ์ ๊ทผํด์ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ ์ ์๋ค.
'TIL (Today I Learned) > Unity' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Unity, MacOS] LeanTween (0) | 2021.09.17 |
---|---|
[Unity]iOS14 ์จ๋ฒ์ ์ฌ์ง ์ ์ฅ (0) | 2021.08.29 |
[Unity] iOS build path issue (0) | 2021.08.27 |