create Umaterial using UTexture2D

Hi friends.

I don’t know how to import a bmp file on disk from this source and apply it to dynamic material using UTexture2D.

How to create UMaterial using UTexture2D ??


IsValid = false;
UTexture2D* LoadedT2D = NULL;

IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));

IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat));

//Load From File
TArray<uint8> RawFileData;
if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath))
{
	return NULL;
}


//Create T2D!
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
	const TArray<uint8>* UncompressedBGRA = NULL;
	if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
	{
		LoadedT2D = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);

		//Valid?
		if (!LoadedT2D)
		{
			return NULL;
		}

		//Out!
		Width = ImageWrapper->GetWidth();
		Height = ImageWrapper->GetHeight();

		//Copy!
		void* TextureData = LoadedT2D->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
		FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
		LoadedT2D->PlatformData->Mips[0].BulkData.Unlock();

		//Update!
		LoadedT2D->UpdateResource();
	}
}

// Success!
IsValid = true;
return LoadedT2D;

Materials generally wrap textures and extend their functionality to meshes and other use cases for rendering purposes. You probably want to create a material in editor that takes a texture parameter as and then in a dynamic instance of that material set its texture parameter to the texture you desire.
This should be super useful:

-Spiris