GAME Dev/Tip
유니티 이미지 sprite를 ios/android에 저장하기
루피캣
2023. 9. 24. 20:20
반응형
유니티에서 이미지를 디바이스에 저장하기 위해
Native Gallery for Android & iOS 애셋을 사용할 수 있다.
https://assetstore.unity.com/packages/tools/integration/native-gallery-for-android-ios-112630
Native Gallery for Android & iOS | 기능 통합 | Unity Asset Store
Use the Native Gallery for Android & iOS from yasirkula on your next project. Find this integration tool & more on the Unity Asset Store.
assetstore.unity.com
패키지를 import하고
이미지의 Sprite에서 Texture2D 객체를 뽑아와서
NativeGallery의 SaveImageToGallery 함수를 호출한다.
이미지 path로도 가능
Texture2D texture = sampleImage.sprite.texture;
NativeGallery.Permission permission = NativeGallery.SaveImageToGallery(texture, albumName, fileName + ".png",
(success, path) => Debug.Log("Image save result: " + success + " " + path));
Debug.Log("Permission result: " + permission);
io, andriod 기기에서 사용자 앨범에 접근한다는 동의 팝업이 뜨고 앨범에 저장된걸 확인할 수 있다.
스트린캡의 Texture2D는 아래의 코드를 save하면 된다.
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
반응형