# TextureCache class

Namespace: [Rhino.Display](https://developer.rhino3d.com/api/rhinocommon/namespace/rhino.display.md) · Assembly: [RhinoCommon](https://developer.rhino3d.com/api/rhinocommon/assembly/rhinocommon.md) · Since v9.0

```cs
public static class TextureCache
```

An application-wide cache of textures whose pixels live in memory rather than in a file on disk.

Rhino identifies a texture by a name. Normally that name is the path of an image file, but it does not have to be: a name registered here shadows the file system, so any texture that refers to the name - a [Texture](https://developer.rhino3d.com/api/rhinocommon/type/rhino.docobjects.texture.md), a [DisplayMaterial](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.displaymaterial.md), a [Material](https://developer.rhino3d.com/api/rhinocommon/type/rhino.docobjects.material.md) - draws the pixels registered here instead of reading a file.

Calling [TextureCache.Set(string, Bitmap)](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/set.md) again with the same name replaces the pixels in place.

**Remarks:** The cache is per-session and per-application, not per-document: names are shared by every open document and nothing here is saved in the 3dm file. Entries are held until [TextureCache.Remove(string)](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/remove.md) is called, so a tool that creates names dynamically should remove the ones it is finished with.

**Example:**

```cs
var bitmap = new System.Drawing.Bitmap(512, 512);
// ...paint into bitmap...
Rhino.Display.TextureCache.Set("MyPaintTool:canvas", bitmap);
material.SetBitmapTexture("MyPaintTool:canvas");
doc.Views.Redraw();
```

## Methods

- [Contains](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/contains.md): (static) Determines whether a texture is registered under the given name.
- [GetSize](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/getsize.md): (static) Gets the pixel size of the texture registered under the given name.
- [Remove](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/remove.md): (static) Removes the texture registered under the given name and frees its pixels. Anything still pointing at the name falls back to looking for an image file called that, so remove a name only once nothing is drawing it.
- [Set](https://developer.rhino3d.com/api/rhinocommon/type/rhino.display.texturecache/set.md): (static) Registers, or replaces the pixels of, the in-memory texture with the given name. The bitmap's pixels are copied, so the caller stays free to keep painting into the same bitmap and call this again. Replacing the pixels of a name that is already in use invalidates the copy the display holds on the GPU, so the new pixels appear on the next redraw of any viewport that draws the texture.
