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
graphicsDevice
GraphicsDevicewidth
intheight
int
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
graphicsDevice
GraphicsDevicewidth
intheight
intmipmap
boolformat
SurfaceFormat
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
graphicsDevice
GraphicsDevicewidth
intheight
intmipmap
boolformat
SurfaceFormattype
Texture2D.SurfaceTypeshared
boolarraySize
int
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
graphicsDevice
GraphicsDevicewidth
intheight
intmipmap
boolformat
SurfaceFormatarraySize
int
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
graphicsDevice
GraphicsDeviceThe graphics device to use to create the texture.
path
stringThe 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
graphicsDevice
GraphicsDeviceThe graphics device to use to create the texture.
path
stringThe path to the image file.
colorProcessor
Action<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
graphicsDevice
GraphicsDeviceThe graphics device to use to create the texture.
stream
StreamThe 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
graphicsDevice
GraphicsDeviceThe graphics device to use to create the texture.
stream
StreamThe stream from which to read the image data.
colorProcessor
Action<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
level
intLayer of the texture
arraySlice
intIndex inside the texture array
rect
Rectangle?Area of the texture to retrieve
data
T[]Destination array for the data
startIndex
intStarting index of data where to write the pixel data
elementCount
intNumber 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
level
intLayer of the texture
rect
Rectangle?Area of the texture
data
T[]Destination array for the texture data
startIndex
intFirst position in data where to write the pixel data
elementCount
intNumber 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
data
T[]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
data
T[]Destination array for the texture data
startIndex
intFirst position in data where to write the pixel data
elementCount
intNumber of pixels to read
Type Parameters
T
Reload(Stream)
public void Reload(Stream textureStream)
Parameters
textureStream
Stream
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
level
intLayer of the texture to modify
arraySlice
intIndex inside the texture array
rect
Rectangle?Area to modify
data
T[]New data for the texture
startIndex
intStart position of data
elementCount
int
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
level
intLayer of the texture to modify
rect
Rectangle?Area to modify
data
T[]New data for the texture
startIndex
intStart position of data
elementCount
int
Type Parameters
T
SetData<T>(T[])
Changes the texture's pixels
public void SetData<T>(T[] data) where T : struct
Parameters
data
T[]
Type Parameters
T
New 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