x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Hello, everyone~ I can't load image files successfully when I use Rama's 'Load Texture 2D from File' node...

The code is as follows:

 UTexture2D* UFileOperator::LoadTexture2D_FromFile(const FString& FullFilePath, EJoyImageFormats ImageFormat, bool& IsValid, int32& Width, int32& Height){
     IsValid = false;
     UTexture2D* LoadedT2D = NULL;
     
     IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
     IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(GetJoyImageFormat(ImageFormat));
  
     if (FullFilePath.IsEmpty()) return NULL;
 
     //Load From File
     TArray<uint8> RawFileData;
     if (!FFileHelper::LoadFileToArray(RawFileData, *FullFilePath)) {
         Width = 21;       //Width is 21 if loading fails
         Height = RawFileData.Num();
         return NULL;
     }
 
     if (ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num())) {
         Width = 7;
     }
     else {
         Width = RawFileData.Num();
     }
 
     //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) {
                 Width = 56;
                 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;    
 }

And the blueprint node is

alt text

However, it doesnot load files successfully every time. It loads successfully only a few times... I know the problem is loading problem but not others, because when it fails, the Width is 21 just as what I write in my codes...

I know other developers have already implemented this function, so help please. Thanks:)

Product Version: UE 4.13
Tags:
blueprint.png (23.4 kB)
more ▼

asked Nov 17 '16 at 12:53 PM in Using UE4

avatar image

Yunze Gu
63 16 18 22

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

your blueprint node shows E:\29db.jpg and you have selected the file format of .png so I assume that must be making your attempt to load a file from E:\29db.jpg.png

more ▼

answered Apr 16 '17 at 08:08 PM

avatar image

BaconGaming97
16 2 7 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question