개발관련/Unity

could not create asset from file could not be read

Diademata 2021. 1. 6. 10:21
반응형

유니티 버전 업을 한 후 이미지 파일이 깨지는 경우가 발생한다. 

 

간단한 해결 방법은 디자이너를 괴롭히는 방법으로 이미지를 포멧 방식을 바꿔서 새롭게 Export를 요청한다.

 

또는 C#으로 Png 이미지의 메타 정보를 수정하는 방법이 있다.

 

정상적인 이미지의 메타 정보와 비정상적으로 보이는 메타 정보를 비교하여 빠진 메타 정보를 삽입해주면 된다.

 

응용하면 재귀로 모든 이미지 파일 검색하여 빠진 메타 정보를 삽입해 줄 수 있다.

 

Code>>

 

using System;
using System.Drawing;
using System.IO;
using System.Windows;

namespace ReadPngSample
{
    class Program
    {
        static void Main(string[] args)
        {

            var bmp = new Bitmap($@"NormalSample.png");
            
            var propItems = bmp.PropertyItems;
            foreach (System.Drawing.Imaging.PropertyItem items in propItems)
            {
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                Console.WriteLine(items.Type + " : " + items.Id + " = " + items.Value.ToString() + "(len : " + items.Len + ")");
            }
            Console.WriteLine();
 
            //빠진 메타 정보임
            var prop = bmp.GetPropertyItem(305);
            bmp = new Bitmap($@"ErrorImamge.png");
            //메타 정보 삽입
            bmp.SetPropertyItem(prop);
            propItems = bmp.PropertyItems;
            foreach (System.Drawing.Imaging.PropertyItem items in propItems)
            {
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                Console.WriteLine(items.Type + " : " + items.Id + " = " + items.Value.ToString() + "(len : " + items.Len + ")");
            }
            Console.WriteLine();
            bmp.Save($@"NewErrorImamge.png");
            Console.ReadKey();
        }
    }
}

 

 

반응형