> 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/graphicsoptions/textureloadingcolorkey.md).

# TextureLoadingColorKey

### Introduction

The GraphicsOptions' TextureLoadingColorKey allows you to set the color to ignore when loading .bmp graphics. **The TextureLoadingColorKey value is only applied to .bmp images and not to other images.** The reason for this is because other image formats either:

* Have lossy compression so exact colors are not preserved and color keys are not an effective way to create transparency.
* Include an alpha channel which include the ability to have partial transparency.

### Code Example

The following code creates a [Sprite](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) from a graphic which has a magenta background. The bool ifUsingColorKey controls whether the color key is set to Magenta or not - the default color is Black. Files used: Add the following to Initialize after initializing FlatRedBall:

```
bool ifUsingColorKey = true;

if (ifUsingColorKey)
{
    // Set the color key to Magenta:
    FlatRedBallServices.GraphicsOptions.TextureLoadingColorKey =
        Microsoft.Xna.Framework.Graphics.Color.Magenta;
}

// Create a Sprite
SpriteManager.AddSprite("redballWithMagenta.bmp");
```

Setting the ifUsingColorKey to false will result in a magenta box being drawn around the redball graphic. ![ColorKey.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-09ff62c62c8892f5e912c48282d55195f077c234%2Fmigrated_media-ColorKey.png?alt=media)

### ColorKey and Texture caching

You may be wondering why the above tutorial requires a recompile and a change of the bool instead of simply creating two [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) with a change in the TextureLoadingColorKey between the creation of the two [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). The reason for this is because [FlatRedBallServices](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) [caches](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). Therefore an actual load is only performed the **first** time that the redball.bmp graphic is referenced. Every subsequent time, the texture reference to the cached texture data is returned. The exception to this is if different [content managers](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php#Content_Manager_Code_Sample) are used.


---

# 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/graphicsoptions/textureloadingcolorkey.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.
