사용자가 이미지를 올리면 자동으로 저장되고
앱을 재실행하면 이미지를 불러오는건데
재실행할때 왜 안 뜰까?
코드에 문제 있는지좀;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class LoadGallery : MonoBehaviour
{
public RawImage img;
void Start()
{
if (File.Exists(Application.persistentDataPath + "/Image"))
{
File.ReadAllBytes(Application.persistentDataPath + "/Image" + "/저장.jpg");
}
}
public void OnClickImageLoad()
{
NativeGallery.GetImageFromGallery((file) =>
{
FileInfo seleted = new FileInfo(file);
if(seleted.Length > 100000000)
{
return;
}
if(!string.IsNullOrEmpty(file))
{
StartCoroutine(LoadImage(file));
}
});
}
IEnumerator LoadImage(string path)
{
yield return null;
byte[] fileData = File.ReadAllBytes(path);
string filename = Path.GetFileName(path).Split('.')[0];
string name = "저장";
string savePath = Application.persistentDataPath + "/Image";
if(Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
File.WriteAllBytes(savePath + name + ".jpg",fileData);
var temp = File.ReadAllBytes(savePath + filename + ".jpg");
Texture2D tex = new Texture2D(0,0 );
tex.LoadImage(temp);
img.texture = tex;
img.SetNativeSize();
ImageSizeSetting(img, 1000, 1000);
}
void ImageSizeSetting(RawImage img , float x, float y)
{
var imgX = img.rectTransform.sizeDelta.x;
var imgY = img.rectTransform.sizeDelta.y;
if( x / y > imgX / imgY)
{
img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,y);
img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,imgX *(y/imgY));
}
else
{
img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, y);
img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, imgX * (y / imgX));
}
}
}
if(Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } 느낌표 빼먹은듯
이거였나보네;;; 넘 고맙다.....허
그리고 밑에 ImageSizeSetting 함수 보면 imgX * (y / imgX)); imgX *(y/imgY)); 이거 두개중에 하나는 뭔가 잘못된듯.. 대칭이 안맞음
고맙긴 내가 대신 GPT 돌려준 것 뿐인데.. 너도 다음엔 GPT한테 먼저 물어보자