UKismetRenderingLibrary::ImportFileAsTexture2D
UTexture2D* UKismetRenderingLibrary::ImportFileAsTexture2D(UObject* WorldContextObject, const FString& Filename)
{
return FImageUtils::ImportFileAsTexture2D(Filename);
}
UTexture2D* FImageUtils::ImportFileAsTexture2D(const FString& Filename)
{
UTexture2D* NewTexture = nullptr;
TArray64<uint8> Buffer;
// 파일을 버퍼로 읽어온다.
// Load a binary file to a dynamic array with two uninitialized bytes at end as padding.
if (FFileHelper::LoadFileToArray(Buffer, *Filename))
{
// 버퍼를 Texture2D 타입으로 변환
NewTexture = FImageUtils::ImportBufferAsTexture2D(Buffer);
if(!NewTexture)
{
UE_LOG(LogImageUtils, Warning, TEXT("Error creating texture. %s is not a supported file format"), *Filename);
}
}
else
{
UE_LOG(LogImageUtils, Warning, TEXT("Error creating texture. %s could not be found"), *Filename);
}
return NewTexture;
}