# Accessing pixel values of Texture2D

**URL:** <https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798>\
**Category:** Asset Creation\
**Tags:** unreal-engine, pixel, question\
**Created:** [April 6, 2014, 8:38pm UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798 "2014-04-06T20:38:40Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Al\_Ananias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Al\_Ananias](https://forums.unrealengine.com/u/Al_Ananias)\
**Post date:** [August 14, 2020, 3:52pm UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798/21 "2020-08-14T15:52:33Z")

</div>

Massive sorry for necroing this topic. I used the code proposed by and it worked perfectly in development. Sadly when I finished the project and am building it for my target platform (iOS) I get this error:

```
UATHelper: Packaging (iOS): [113/541] Compile MazeOnGameModeBase.cpp
UATHelper: Packaging (iOS): C:\Users\aless\Documents\Unreal Projects\MazeOn\Source\MazeOn\MasterMaze.cpp:84:23: error: static_cast from 'unsigned char *' to 'FColor *' is not allowed
UATHelper: Packaging (iOS): FColor* MazeLayout = static_cast<FColor*>(Layout->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_ONLY));
UATHelper: Packaging (iOS): ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PackagingResults: Error: static_cast from 'unsigned char *' to 'FColor *' is not allowed
UATHelper: Packaging (iOS): [114/541] Compile MasterMaze.gen.cpp

```

Any ideas on how to solve this?

---

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [August 16, 2020, 8:05am UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798/22 "2020-08-16T08:05:08Z")

</div>

I have the same error as Al Ananias. It must be a problem that came with one of the recent unreal engine versions.

---

<div class="post-metadata">

**Author:** ![Al\_Ananias](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Al\_Ananias](https://forums.unrealengine.com/u/Al_Ananias)\
**Post date:** [August 16, 2020, 12:47pm UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798/23 "2020-08-16T12:47:23Z")

</div>

Absolute legend TheKaosSpectrum sorted it in this post: [link text](https://answers.unrealengine.com/questions/977646/view.html)

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [September 28, 2022, 7:36pm UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798/24 "2022-09-28T19:36:34Z")

</div>

> [@anonymous\_user\_b65ae2a21](#):
>
> `uint32 TextureWidth = `

So by your code you are interogating only one pixel here at location x,y of 5,10 ?

I mean not alot in this

```auto
if( PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight )

```

If PixelX that is pixel number 5 is bigger than zero and pixelX is smaller than TextureWidth then do something.

```auto
PixelColor = FormatedImageData[PixelY * TextureWidth + PixelX];

```

So if meets this requirements then it’s added to Pixel Color but this is just 0 to 1 ? where is the mechanism for looking up the shades of gray for the heightmap between black and white there they are.

This is not good for heigthmaps, or maybe I’m wrong and not reading it properly.

So in Pixel color I guess it records the color code or does it record 1 or 0 ?

---

<div class="post-metadata">

**Author:** ![GigiK-K-K](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigiK-K-K](https://forums.unrealengine.com/u/GigiK-K-K)\
**Post date:** [September 29, 2022, 8:25am UTC](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798/25 "2022-09-29T08:25:22Z")

</div>

If anyone can explain what this really represents in the bigger picture of this code.

```auto
uint8 PixelX = 5, PixelY = 10;

```

So is it just the 5,10 x,y coords position on the texture or is it a range that represents an area on the texture ?

[Previous page](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798.md?page=1)
