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

**URL:** <https://forums.unrealengine.com/t/how-to-load-and-display-an-image-from-binary-array-on-console/281344>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [April 23, 2014, 12:49am UTC](https://forums.unrealengine.com/t/how-to-load-and-display-an-image-from-binary-array-on-console/281344 "2014-04-23T00:49:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 23, 2014, 12:49am UTC](https://forums.unrealengine.com/t/how-to-load-and-display-an-image-from-binary-array-on-console/281344/1 "2014-04-23T00:49:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 23, 2014, 2:34am UTC](https://forums.unrealengine.com/t/how-to-load-and-display-an-image-from-binary-array-on-console/281344/2 "2014-04-23T02:34:10Z")

</div>

#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();

```

}
