How to load and display an image from binary array on console?

Dear Friends at Epic,

I just noticed that FImageUtils::CreateTexture2D does not work on consoles!

/**
 * Creates a 2D texture from a array of raw color data.
 *
 * @param SrcWidth		Source image width.
 * @param SrcHeight		Source image height.
 * @param SrcData		Source image data.
 * @param Outer			Outer for the texture object.
 * @param Name			Name for the texture object.
 * @param Flags			Object flags for the texture object.
 * @param InParams		Params about how to set up the texture.
 * @return				Returns a pointer to the constructed 2D texture object.
 *
 */
UTexture2D* FImageUtils::CreateTexture2D(int32 SrcWidth, int32 SrcHeight, const TArray<FColor> &SrcData, UObject* Outer, const FString& Name, const EObjectFlags &Flags, const FCreateTexture2DParameters& InParams)
{
#if WITH_EDITORONLY_DATA

How can I load an image that is saved to hard disk into a Texture2D on console?

or in a packaged game that is not WITH_EDITOR ?

Rama

#Wrote My Own Version

This version is basically instant and does not have any Editor Only Dependency because it does not use PostEditChange()

The core code is taken from FImageUtils::CreateTexture2D, but with some changes.

One notable feature is I made the SrcPtr const.

void AYourClass::TextureFromImage_Internal(const int32 SrcWidth, const int32 SrcHeight, const TArray &SrcData, const bool UseAlpha)
{
	// Create the texture
	MyScreenshot = UTexture2D::CreateTransient(
		SrcWidth, 
		SrcHeight, 
		PF_B8G8R8A8
	);
	
	// Lock the texture so it can be modified
	uint8* MipData = static_cast<uint8*>(MyScreenshot->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));

	// Create base mip.
uint8* DestPtr = NULL;
const FColor* SrcPtr = NULL;
for( int32 y=0; y<SrcHeight; y++ )
{
	DestPtr = &MipData[(SrcHeight - 1 - y) * SrcWidth * sizeof(FColor)];
	SrcPtr = const_cast<FColor*>(&SrcData[(SrcHeight - 1 - y) * SrcWidth]);
	for( int32 x=0; x<SrcWidth; x++ )
	{
		*DestPtr++ = SrcPtr->B;
		*DestPtr++ = SrcPtr->G;
		*DestPtr++ = SrcPtr->R;
		if( UseAlpha )
		{
			*DestPtr++ = SrcPtr->A;
		}
		else
		{
			*DestPtr++ = 0xFF;
		}
		SrcPtr++;
	}
}

// Unlock the texture
MyScreenshot->PlatformData->Mips[0].BulkData.Unlock();
MyScreenshot->UpdateResource();

}