> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/graphics/texture/imagedata.md).

# ImageData

### Introduction

The ImageData class represents modifiable data that can be created from a [Texture2D](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), or be used to construct a [Texture2D](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). The ImageData class can be used to easily interact with the [Texture2D](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) class, and also provides a cross-platform way of creating and modifying textures.

### Creating Textures

Add the following using statements:

```
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;
using Color = Microsoft.Xna.Framework.Graphics.Color;
using FlatRedBall.Graphics.Texture;
```

Add the following to Initialize after initializing FlatRedBall:

```
ImageData imageData = new ImageData(32, 32);

imageData.Fill(Color.Blue);

// let's plot some random pixels:

for (int i = 0; i < 50; i++)
{
    int randomX = FlatRedBallServices.Random.Next(
        imageData.Width);
    int randomY = FlatRedBallServices.Random.Next(
        imageData.Height);

    imageData.SetPixel(randomX, randomY, Color.Yellow);
}

// Create the texture
Texture2D texture2D = imageData.ToTexture2D();
// Give it a name.  Make sure this is unique!
texture2D.Name = "MyDynamicTexture";

// We will want to associate the created Texture2D with a
// ContentManager.  If you're in a Screen, use the Screen's
// ContentManager.  Here we'll just make one up:
FlatRedBallServices.AddDisposable(
    texture2D.Name,
    texture2D,
    "MyContentManager");

// Finally, let's use this Texture so we can actually see it
Sprite sprite = SpriteManager.AddSprite(texture2D);

// Set these numbers higher if using FSB or if you're in pixel
// pixel coordinates:
sprite.ScaleX = 10;
sprite.ScaleY = 10;
```

![ImageDataToTexture2D.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-38dff82305728a31fff9db8a35a7d11760f26ba8%2Fmigrated_media-ImageDataToTexture2D.png?alt=media)

**Note:** This code uses the Color and Texture2D classes. Remember, if you are using a version of FlatRedBall other than FlatRedBall XNA, your using statements will be different. For more information, see:

* [Microsoft.Xna.Framework.Graphics.Texture2D](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [Microsoft.Xna.Framework.Graphics.Color](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

### Additional Information

* [Fog of war using ImageData with source and in-browser FSB demo.](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

### ImageData Members

* [FlatRedBall.Graphics.Texture.ImageData.ApplyColorOperation](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)
* [FlatRedBall.Graphics.Texture.ImageData.Fill](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php)

Did this article leave any questions unanswered? Post any question in our [forums](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/forum.md) for a rapid response.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/graphics/texture/imagedata.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
