# Proper way to convert from UTextureRenderTarget2D into UTexture2D?

**URL:** <https://forums.unrealengine.com/t/proper-way-to-convert-from-utexturerendertarget2d-into-utexture2d/394683>\
**Category:** Rendering\
**Tags:** unreal-engine, Android, Rendering, CPP, question\
**Created:** [May 26, 2017, 1:56pm UTC](https://forums.unrealengine.com/t/proper-way-to-convert-from-utexturerendertarget2d-into-utexture2d/394683 "2017-05-26T13:56:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.noorgames](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@david.noorgames](https://forums.unrealengine.com/u/david.noorgames)\
**Post date:** [May 26, 2017, 1:56pm UTC](https://forums.unrealengine.com/t/proper-way-to-convert-from-utexturerendertarget2d-into-utexture2d/394683/1 "2017-05-26T13:56:10Z")

</div>

Hello,  
I want to convert a captured screen of game into UTexture2D. Here’s what has been done.

I have inherited a custom class AScreenCapture2D from ASceneCapture2D, with member

```
UPROPERTY()
        UTexture2D* m_photo;

```

and added these functions.

```
void AScreenCapture2D::SetRenderedTexture()
{
    USceneCaptureComponent2D* captureComponent = GetCaptureComponent2D();
    UTextureRenderTarget2D* renderTarget = captureComponent->TextureTarget;
    checkf(renderTarget != nullptr, TEXT("renderTarget is null"));

    captureComponent->UpdateContent();

    m_photo = ConvertRenderTargetToTexture2D(renderTarget);
    checkf(m_photo != nullptr, TEXT("photo is null"));
}

UTexture2D* AScreenCapture2D::ConvertRenderTargetToTexture2D(UTextureRenderTarget2D* TextureRenderTarget)
{
    // Creates Texture2D to store TextureRenderTarget content
    UTexture2D *Texture = UTexture2D::CreateTransient(TextureRenderTarget->SizeX, TextureRenderTarget->SizeY);
#if WITH_EDITORONLY_DATA
    Texture->MipGenSettings = TMGS_NoMipmaps;
#endif
    Texture->SRGB = false;
    Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;

    // Read the pixels from the RenderTarget and store them in a FColor array
    TArray<FColor> SurfData;
    FRenderTarget *RenderTarget = TextureRenderTarget->GameThread_GetRenderTargetResource();
    RenderTarget->ReadPixels(SurfData);

    // Lock and copies the data between the textures
    void* TextureData = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
    const int32 TextureDataSize = SurfData.Num() * 4;
    FMemory::Memcpy(TextureData, SurfData.GetData(), TextureDataSize);
    Texture->PlatformData->Mips[0].BulkData.Unlock();
    // Apply Texture changes to GPU memory
    Texture->UpdateResource();

    return Texture;
}

UTexture2D* AScreenCapture2D::GetRenderedTexture() const
{
    checkf(m_photo != nullptr, TEXT("photo is null"));

    return m_photo;
}

```

The second function I found from one of answers here, and adapted it a little bit.

Now for testing purposes I made a UMG widget with initial white image and tried to render that UTexture2D photo.

 ![139283-capture0.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/d/fdd0e405448d39917a90a3cbfac0f17e7550576d.png)

The code above works for windows with editor, but fails on android. The white colored background image disappears, and I get a transparent image.

This is the changed settings of UTextureRenderTarget2D

![139285-capture1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/c/73c59dcfde061dfae8640bed3f9e8862ed3a7891.png)

So if this method is a correct way to convert UTextureRenderTarget2D into UTexture2D, then how to fix this issue with android rendering?  
If not, then what’s the proper way for conversion?

P.S: I know about ConstructTexture2D, but it works only with editor.
