" Texturefromdisk " ) staticclass utexture2d* gettexture2dfromdiskfile (const fstring& FilePath);
classutexture2d* Utexturefromdiskfunctionlibrary::gettexture2dfromdiskfile (Constfstring&FilePath) {Tarray<uint8>Rawfiledata; Utexture2d* Mytexture =NULL; if(Ffilehelper::loadfiletoarray (Rawfiledata, *filepath/*"<path to File>"*/) ) {Iimagewrappermodule& imagewrappermodule = fmodulemanager::loadmodulechecked<iimagewrappermodule> (FName ("Imagewrapper")); //note:png format. Other formats is supportedIimagewrapperptr Imagewrapper =Imagewrappermodule.createimagewrapper (eimageformat::P ng); if(Imagewrapper.isvalid () && imagewrapper->setcompressed (Rawfiledata.getdata (), Rawfiledata.num ())) { Consttarray<uint8>* Uncompressedbgra =NULL; if(Imagewrapper->getraw (Ergbformat::bgra,8, Uncompressedbgra)) { //Create the utexture for renderingMytexture = Utexture2d::createtransient (Imagewrapper->getwidth (), imagewrapper->getheight (), pf_b8g8r8a8); //Fill in the source data from the file void* Texturedata = mytexture->platformdata->mips[0]. Bulkdata.lock (Lock_read_write); fmemory::memcpy (Texturedata, Uncompressedbgra->getdata (), uncompressedbgra->Num ()); Mytexture->platformdata->mips[0]. Bulkdata.unlock (); //Update The rendering resource from data.Mytexture->Updateresource (); } } } returnMytexture;}
Don't forget the reference to the header file
" Developer/imagewrapper/public/interfaces/iimagewrapper.h " "developer/imagewrapper/public/interfaces/iimagewrappermodule.h"
UE4 local image to Utexture2d in runtime display