# How can I save a RenderTarget or a Texture to a file?

**URL:** <https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398>\
**Category:** Asset Creation\
**Tags:** scenecapturecomponen, scenecapture2d, save-file, unreal-engine, question\
**Created:** [November 13, 2015, 6:10pm UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398 "2015-11-13T18:10:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddbrown30](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ddbrown30](https://forums.unrealengine.com/u/ddbrown30)\
**Post date:** [November 13, 2015, 6:10pm UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/1 "2015-11-13T18:10:25Z")

</div>

I’ve seen this question asked in a few different ways, but no one seems to be able to give a definitive answer.

To sum up, I’m using a SceneCaptureComponent2D to render to a RenderTarget. I want to save that RenderTarget to disk, at runtime. Everything with this is working fine, I just don’t know how to do the last step of saving it to a file.

To be more explicit on what I’m trying to create, we have a literal camera in our game that the player can use to take pictures. We want to save these pictures to disk so that the player can share them.

A solution in Blueprint is preferred, but C++ is not a problem.

---

<div class="post-metadata">

**Author:** ![Slavq](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavq](https://forums.unrealengine.com/u/Slavq)\
**Post date:** [January 10, 2016, 7:05pm UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/2 "2016-01-10T19:05:56Z")

</div>

+1 I would also like to know this.

---

<div class="post-metadata">

**Author:** ![ddbrown30](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ddbrown30](https://forums.unrealengine.com/u/ddbrown30)\
**Post date:** [January 11, 2016, 3:00pm UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/3 "2016-01-11T15:00:59Z")

</div>

I wasn’t able to find anything built in, so I ended up writing something myself. I’m relying on FHighResScreenshotConfig, as it already does most of the work. You could probably dig into it if you need more control.

The loop to set the alpha was a bit of a hack fix. For some reason, the alpha isn’t set correctly on the render target, so you need to manually set it before saving.

```
void SaveRenderTargetToDisk( UTextureRenderTarget2D* InRenderTarget, FString Filename )
{
    FTextureRenderTargetResource* RTResource = InRenderTarget->GameThread_GetRenderTargetResource();

    FReadSurfaceDataFlags ReadPixelFlags( RCM_UNorm );
    ReadPixelFlags.SetLinearToGamma( true );

    TArray<FColor> OutBMP;
    RTResource->ReadPixels( OutBMP, ReadPixelFlags );

    for( FColor& color : OutBMP )
    {
        color.A = 255;
    }

    FIntRect SourceRect;

    FIntPoint DestSize( InRenderTarget->GetSurfaceWidth(), InRenderTarget->GetSurfaceHeight() );

    FString ResultPath;
    FHighResScreenshotConfig& HighResScreenshotConfig = GetHighResScreenshotConfig();
    HighResScreenshotConfig.SaveImage( Filename, OutBMP, DestSize, &ResultPath );
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5097d118](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5097d118](https://forums.unrealengine.com/u/anonymous_user_5097d118)\
**Post date:** [May 23, 2017, 4:03pm UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/4 "2017-05-23T16:03:46Z")

</div>

Very nice! This was the only thing I could find that got this working! It’s really slow though, saving PNGs takes a lot of time. Do you have any idea how to improve that?

---

<div class="post-metadata">

**Author:** ![yanglong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yanglong](https://forums.unrealengine.com/u/yanglong)\
**Post date:** [August 16, 2017, 6:20am UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/5 "2017-08-16T06:20:24Z")

</div>

it seems not working if I use UTextureRenderTargetCube

---

<div class="post-metadata">

**Author:** ![Jack-Chen8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jack-Chen8](https://forums.unrealengine.com/u/Jack-Chen8)\
**Post date:** [October 30, 2017, 2:46am UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/6 "2017-10-30T02:46:35Z")

</div>

I have not FHighResScreenshotConfig class, Can you give to me? thank you very much.

---

<div class="post-metadata">

**Author:** ![Jack-Chen8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jack-Chen8](https://forums.unrealengine.com/u/Jack-Chen8)\
**Post date:** [October 30, 2017, 5:54am UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/7 "2017-10-30T05:54:28Z")

</div>

I have find the FHighResScreenshotConfig class, and very thanks your guide。 How about if use UTextureRenderTargetCube? expecting answer.

---

<div class="post-metadata">

**Author:** ![sleepdown](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sleepdown](https://forums.unrealengine.com/u/sleepdown)\
**Post date:** [June 6, 2018, 10:34am UTC](https://forums.unrealengine.com/t/how-can-i-save-a-rendertarget-or-a-texture-to-a-file/338398/8 "2018-06-06T10:34:11Z")

</div>

have you find the answer?
