[UE5.0] How to Use A 16bit TIFF File As An Integer Type Array In Blueprint or C++

Hi, I want to read 16bitTIFF with Blueprint or C++.
In Unreal Engine, you can import and use 16bit image data as well as 8bit into the editor, but I couldn’t find a function that can do the same in Blueprint or C++.
(Maybe it’s just my imagination, but…)
After all, is there any other way to refer to an external library (OpenCV or GDAL)?
I am very sorry, but I would appreciate it if you could teach me if possible.

Hi Shino888,

Here’s some fairly generic c++ code that loads any image and gives you access to the data - in the case of 16bit, the format is TSF_RGBA16:

FString PackageName=TEXT("/Game/My16bitImage"); // 
FString AssetName=TEXT("My16bitImage"); // 

UPackage* package=FindPackage(NULL,*PackageName);
if(package) {
	package->FullyLoad();
} else {
	package=LoadPackage(NULL,*PackageName,LOAD_None);
}


UTexture* texture=FindObject<UTexture>(package,*AssetName,true);
if(!texture) {
	texture=(UTexture*)FindObject<UTexture2D>(package,*AssetName,true);
}
if(!texture) {
	texture=(UTexture*)FindObject<UTextureCube>(package,*AssetName,true);
}

if(texture) {

	int32 texWidth=texture->Source.GetSizeX();
	int32 texHeight=texture->Source.GetSizeY();
	ETextureSourceFormat Fmt=texture->Source.GetFormat(); // will be TSF_RGBA16 for a 16bit tiff

	if(Fmt==TSF_RGBA16) {

		uint16* tex1Data=(uint16*)texture->Source.LockMip(0);
	
		// read the data here

		texture->Source.UnlockMip(0);
	}
}

1 Like

Hi, RecourseDesign!!

Thank you for your prompt reply!
I ran the code you provided and it worked!
Thank you very much for the very good solution!
Thank you :slight_smile:

Shino888

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.