以jpg图片为例
UTexture2D* CreateTextureFromFile(const FString& InFileName)
{
TArray<uint8> ImgData;
if (!FFileHelper::LoadFileToArray(ImgData, *InFileName)) return nullptr;
IImageWrapperModule& ImageWrapperModule = FModuleManager::Get().LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::JPEG);
if (ImageWrapper->SetCompressed(ImgData.GetData(), ImgData.Num()))
{
const TArray<uint8>* RawData = nullptr;
ImageWrapper->GetRaw(ERGBFormat::BGRA, ImageWrapper->GetBitDepth(), RawData);
int32 Width = ImageWrapper->GetWidth();
int32 Height = ImageWrapper->GetHeight();
UTexture2D* Texture2D = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
void* MipData = Texture2D->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMem