Class Texture2D
public class Texture2D : Texture, IDisposable
- Inheritance
-
Texture2D
- Implements
- Derived
- Inherited Members
Constructors
Texture2D(GraphicsDevice, int, int)
Creates a new texture of the given size
public Texture2D(GraphicsDevice graphicsDevice, int width, int height)
Parameters
graphicsDeviceGraphicsDevicewidthintheightint
Texture2D(GraphicsDevice, int, int, bool, SurfaceFormat)
Creates a new texture of a given size with a surface format and optional mipmaps
public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format)
Parameters
graphicsDeviceGraphicsDevicewidthintheightintmipmapboolformatSurfaceFormat
Texture2D(GraphicsDevice, int, int, bool, SurfaceFormat, SurfaceType, bool, int)
protected Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format, Texture2D.SurfaceType type, bool shared, int arraySize)
Parameters
graphicsDeviceGraphicsDevicewidthintheightintmipmapboolformatSurfaceFormattypeTexture2D.SurfaceTypesharedboolarraySizeint
Texture2D(GraphicsDevice, int, int, bool, SurfaceFormat, int)
Creates a new texture array of a given size with a surface format and optional mipmaps. Throws ArgumentException if the current GraphicsDevice can't work with texture arrays
public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format, int arraySize)
Parameters
graphicsDeviceGraphicsDevicewidthintheightintmipmapboolformatSurfaceFormatarraySizeint
Properties
Bounds
Gets the dimensions of the texture
public Rectangle Bounds { get; }
Property Value
Height
Gets the height of the texture in pixels.
public int Height { get; }
Property Value
Width
Gets the width of the texture in pixels.
public int Width { get; }
Property Value
Methods
FromFile(GraphicsDevice, string)
Creates a Texture2D from a file, supported formats bmp, gif, jpg, png, tif and dds (only for simple textures). May work with other formats, but will not work with tga files. This internally calls FromStream(GraphicsDevice, Stream, Action<byte[]>).
public static Texture2D FromFile(GraphicsDevice graphicsDevice, string path)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device to use to create the texture.
pathstringThe path to the image file.
Returns
Remarks
Note that different image decoders may generate slight differences between platforms, but perceptually the images should be identical. This call does not premultiply the image alpha, but areas of zero alpha will result in black color data.
FromFile(GraphicsDevice, string, Action<byte[]>)
Creates a Texture2D from a file, supported formats bmp, gif, jpg, png, tif and dds (only for simple textures). May work with other formats, but will not work with tga files. This internally calls FromStream(GraphicsDevice, Stream, Action<byte[]>).
public static Texture2D FromFile(GraphicsDevice graphicsDevice, string path, Action<byte[]> colorProcessor)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device to use to create the texture.
pathstringThe path to the image file.
colorProcessorAction<byte[]>Function that is applied to the data in RGBA format before the texture is sent to video memory. Could be null(no processing then).
Returns
Remarks
Note that different image decoders may generate slight differences between platforms, but perceptually the images should be identical.
FromStream(GraphicsDevice, Stream)
Creates a Texture2D from a stream, supported formats bmp, gif, jpg, png, tif and dds (only for simple textures). May work with other formats, but will not work with tga files.
public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device to use to create the texture.
streamStreamThe stream from which to read the image data.
Returns
Remarks
Note that different image decoders may generate slight differences between platforms, but perceptually the images should be identical. This call does not premultiply the image alpha, but areas of zero alpha will result in black color data.
FromStream(GraphicsDevice, Stream, Action<byte[]>)
Creates a Texture2D from a stream, supported formats bmp, gif, jpg, png, tif and dds (only for simple textures). May work with other formats, but will not work with tga files.
public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream, Action<byte[]> colorProcessor)
Parameters
graphicsDeviceGraphicsDeviceThe graphics device to use to create the texture.
streamStreamThe stream from which to read the image data.
colorProcessorAction<byte[]>Function that is applied to the data in RGBA format before the texture is sent to video memory. Could be null(no processing then).
Returns
Remarks
Note that different image decoders may generate slight differences between platforms, but perceptually the images should be identical.
GetData<T>(int, int, Rectangle?, T[], int, int)
Retrieves the contents of the texture Throws ArgumentException if data is null, data.length is too short or if arraySlice is greater than 0 and the GraphicsDevice doesn't support texture arrays
public void GetData<T>(int level, int arraySlice, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
Parameters
levelintLayer of the texture
arraySliceintIndex inside the texture array
rectRectangle?Area of the texture to retrieve
dataT[]Destination array for the data
startIndexintStarting index of data where to write the pixel data
elementCountintNumber of pixels to read
Type Parameters
T
GetData<T>(int, Rectangle?, T[], int, int)
Retrieves the contents of the texture Throws ArgumentException if data is null, data.length is too short or if arraySlice is greater than 0 and the GraphicsDevice doesn't support texture arrays
public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
Parameters
levelintLayer of the texture
rectRectangle?Area of the texture
dataT[]Destination array for the texture data
startIndexintFirst position in data where to write the pixel data
elementCountintNumber of pixels to read
Type Parameters
T
GetData<T>(T[])
Retrieves the contents of the texture Throws ArgumentException if data is null, data.length is too short or if arraySlice is greater than 0 and the GraphicsDevice doesn't support texture arrays
public void GetData<T>(T[] data) where T : struct
Parameters
dataT[]Destination array for the texture data
Type Parameters
T
GetData<T>(T[], int, int)
Retrieves the contents of the texture Throws ArgumentException if data is null, data.length is too short or if arraySlice is greater than 0 and the GraphicsDevice doesn't support texture arrays
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
dataT[]Destination array for the texture data
startIndexintFirst position in data where to write the pixel data
elementCountintNumber of pixels to read
Type Parameters
T
Reload(Stream)
public void Reload(Stream textureStream)
Parameters
textureStreamStream
SaveAsJpeg(Stream, int, int)
Converts the texture to a JPG image
public void SaveAsJpeg(Stream stream, int width, int height)
Parameters
SaveAsPng(Stream, int, int)
Converts the texture to a PNG image
public void SaveAsPng(Stream stream, int width, int height)
Parameters
SetData<T>(int, int, Rectangle?, T[], int, int)
Changes the pixels of the texture Throws ArgumentNullException if data is null Throws ArgumentException if arraySlice is greater than 0, and the GraphicsDevice does not support texture arrays
public void SetData<T>(int level, int arraySlice, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
Parameters
levelintLayer of the texture to modify
arraySliceintIndex inside the texture array
rectRectangle?Area to modify
dataT[]New data for the texture
startIndexintStart position of data
elementCountint
Type Parameters
T
SetData<T>(int, Rectangle?, T[], int, int)
Changes the pixels of the texture
public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
Parameters
levelintLayer of the texture to modify
rectRectangle?Area to modify
dataT[]New data for the texture
startIndexintStart position of data
elementCountint
Type Parameters
T
SetData<T>(T[])
Changes the texture's pixels
public void SetData<T>(T[] data) where T : struct
Parameters
dataT[]
Type Parameters
TNew data for the texture
SetData<T>(T[], int, int)
Changes the texture's pixels
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
Type Parameters
T