UE4 local image to Utexture2d in runtime display

Source: Internet
Author: User

" 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.