# Save UTexture2D as 8-bit or 16-bit PNG C++

**URL:** <https://forums.unrealengine.com/t/save-utexture2d-as-8-bit-or-16-bit-png-c/1240708>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [July 26, 2023, 2:29pm UTC](https://forums.unrealengine.com/t/save-utexture2d-as-8-bit-or-16-bit-png-c/1240708 "2023-07-26T14:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schurkee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schurkee](https://forums.unrealengine.com/u/Schurkee)\
**Post date:** [July 26, 2023, 2:29pm UTC](https://forums.unrealengine.com/t/save-utexture2d-as-8-bit-or-16-bit-png-c/1240708/1 "2023-07-26T14:29:45Z")

</div>

I aim to create a Heightmap generated via C++ and then used for the landscape!  
I managed to generate the UTexture2D and Save it as PNG but I get this when trying to import the png file to the landscape:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/2/c92ef666ef770f7bdd97f935da86919f957e2cdc.png)

When I tried to figure out what was wrong I found that the png file was saved either as 32bit using

> FImageUtils::PNGCompressImageArray(Width, Height, Colors, ImgData);

or 24bit using

> FImageUtils::ThumbnailCompressImageArray(Width, Height, Colors, ImgData);

Does anyone have any idea how to save it as 16-bit or 8-bit png? I searched everywhere and I couldn’t find any solution!

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![dagon1999](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dagon1999](https://forums.unrealengine.com/u/dagon1999)\
**Post date:** [July 27, 2023, 4:33am UTC](https://forums.unrealengine.com/t/save-utexture2d-as-8-bit-or-16-bit-png-c/1240708/2 "2023-07-27T04:33:39Z")

</div>

> [@Schurkee](#):
>
> FImageUtils

you can try IImageWrapper::SetRaw with InFormat= Gray

> **[IImageWrapper::SetRaw](https://docs.unrealengine.com/4.27/en-US/API/Runtime/ImageWrapper/IImageWrapper/SetRaw/)**
>
> Sets the compressed data.

---

<div class="post-metadata">

**Author:** ![Schurkee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schurkee](https://forums.unrealengine.com/u/Schurkee)\
**Post date:** [July 28, 2023, 1:43pm UTC](https://forums.unrealengine.com/t/save-utexture2d-as-8-bit-or-16-bit-png-c/1240708/3 "2023-07-28T13:43:06Z")

</div>

I tried so many settings and methods and the best result is a blown-out image with somehow a different pattern than the original texture!  
 ![Original Texture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/1/9f128e75958e03743a6069ac5520a50139c48004.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/7/f076f1e751137ca4ac399ba34d986d29aba6c001.png)
