I’m loading a texture2d from file using IImageWrapper but the loaded texture is always a single flat color. Is there anything that would cause this? I would really appreciate some help with this.
I’m using pretty much the same code as in Rama’s victory BP
ImageLoader::ImageLoader()
{
TArray RawFileData;
FString NewPath=FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
NewPath+=“bitmapImage.bmp”;
std::string newstring=TCHAR_TO_UTF8(*NewPath);
std::ifstream inputFile(newstring);
FString HappyString(newstring.c_str()); //this is the full path
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
// Note: PNG format. Other formats are supported
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::BMP);
if (FFileHelper::LoadFileToArray(RawFileData, *HappyString))
{
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
const TArray<uint8>* UncompressedBGRA = NULL;
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
{
mytex = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::FromInt(RawFileData.Num()));
//oh yes, you need copy the loaded data onto texture:
//mytex->MipGenSettings = TMGS_NoMipmaps;
void* TextureData = mytex->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, UncompressedBGRA->GetData(), UncompressedBGRA->Num());
mytex->PlatformData->Mips[0].BulkData.Unlock();
// Update the rendering resource from data.
mytex->UpdateResource();
}
}
}
}