Microsoft.Xna.Framework.Graphics
Class Texture2D

java.lang.Object
  extended by Microsoft.Xna.Framework.Graphics.GraphicsResource
      extended by Microsoft.Xna.Framework.Graphics.Texture
          extended by Microsoft.Xna.Framework.Graphics.Texture2D
All Implemented Interfaces:
IDisposable
Direct Known Subclasses:
RenderTarget2D

public class Texture2D
extends Texture

Represents a 2D grid of texels.

Author:
Halofreak1990

Field Summary
protected  int height
           
protected  int width
           
 
Fields inherited from class Microsoft.Xna.Framework.Graphics.GraphicsResource
_parent, Disposing, Name, Tag
 
Constructor Summary
protected Texture2D()
           
  Texture2D(GraphicsDevice graphicsDevice, int width, int height)
          Creates a new instance of this object.
  Texture2D(GraphicsDevice graphicsDevice, int width, int height, boolean mipMap, SurfaceFormat format)
          Creates a new instance of this object.
 
Method Summary
 Rectangle Bounds()
          Gets the size of this resource.
protected  void Dispose(boolean disposing)
          Immediately releases the unmanaged resources used by this Object.
static Texture2D FromStream(GraphicsDevice graphicsDevice, java.io.InputStream stream)
          Loads texture data from a stream.
static Texture2D FromStream(GraphicsDevice graphicsDevice, java.io.InputStream stream, int width, int height, boolean zoom)
          Loads texture data from a stream.
<T> void
GetData(int level, Rectangle rect, T[] data, int startIndex, int elementCount)
          Gets a copy of 2D texture data, specifying a mipmap level, source rectangle, start index, and number of elements.
<T> void
GetData(T[] data)
          Gets a copy of 2D texture data.
<T> void
GetData(T[] data, int startIndex, int elementCount)
          Gets a copy of 2D texture data, specifying a start index and number of elements.
 int Height()
          Gets the height of this texture resource, in pixels.
 void SaveAsJpeg(java.io.OutputStream stream, int width, int height)
          Saves texture data as a .jpg.
 void SaveAsPng(java.io.OutputStream stream, int width, int height)
          Saves texture data as a .png.
<T> void
SetData(int level, Rectangle rect, T[] data, int startIndex, int elementCount)
          Sets 2D texture data, specifying a mipmap level, source rectangle, start index, and number of elements.
<T> void
SetData(T[] data)
          Sets 2D texture data.
<T> void
SetData(T[] data, int startIndex, int elementCount)
          Sets 2D texture data, specifying a start index, and number of elements.
 int Width()
          Gets the width of this texture resource, in pixels.
 
Methods inherited from class Microsoft.Xna.Framework.Graphics.Texture
Format, LevelCount
 
Methods inherited from class Microsoft.Xna.Framework.Graphics.GraphicsResource
Dispose, finalize, GraphicsDevice, IsDisposed, raise_disposing, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

height

protected int height

width

protected int width
Constructor Detail

Texture2D

protected Texture2D()

Texture2D

public Texture2D(GraphicsDevice graphicsDevice,
                 int width,
                 int height)
Creates a new instance of this object.

Parameters:
graphicsDevice - The device.
width - Texture width.
height - Texture height.

Texture2D

public Texture2D(GraphicsDevice graphicsDevice,
                 int width,
                 int height,
                 boolean mipMap,
                 SurfaceFormat format)
Creates a new instance of this object.

Parameters:
graphicsDevice - The device.
width - Texture width.
height - Texture height.
mipMap - True to generate a full mipmap chain; false otherwise.
format - Texture data format.
Method Detail

Bounds

public Rectangle Bounds()
Gets the size of this resource.


Width

public int Width()
Gets the width of this texture resource, in pixels.


Height

public int Height()
Gets the height of this texture resource, in pixels.


Dispose

protected void Dispose(boolean disposing)
Description copied from class: GraphicsResource
Immediately releases the unmanaged resources used by this Object.

Overrides:
Dispose in class GraphicsResource

FromStream

public static Texture2D FromStream(GraphicsDevice graphicsDevice,
                                   java.io.InputStream stream)
Loads texture data from a stream.

Parameters:
graphicsDevice - A graphics device.
stream - Data stream from one of the following file types: .gif, .jpg or .png.
Returns:
The created texture.

FromStream

public static Texture2D FromStream(GraphicsDevice graphicsDevice,
                                   java.io.InputStream stream,
                                   int width,
                                   int height,
                                   boolean zoom)
Loads texture data from a stream.

Parameters:
graphicsDevice - A graphics device.
stream - Data stream from one of the following file types: .gif, .jpg or .png.
width - The requested image width.
height - The requested image height.
zoom - Control the aspect ratio when zooming (scaling); set to false to maintain a constant aspect ratio, true otherwise. See remarks.
Returns:
The created texture.

GetData

public <T> void GetData(T[] data)
Gets a copy of 2D texture data. Reference page contains code sample.

Parameters:
data - Array of data.

GetData

public <T> void GetData(T[] data,
                        int startIndex,
                        int elementCount)
Gets a copy of 2D texture data, specifying a start index and number of elements. Reference page contains code sample.

Parameters:
data - Array of data.
startIndex - Index of the first element to get.
elementCount - Number of elements to get.

GetData

public <T> void GetData(int level,
                        Rectangle rect,
                        T[] data,
                        int startIndex,
                        int elementCount)
Gets a copy of 2D texture data, specifying a mipmap level, source rectangle, start index, and number of elements.

Parameters:
level - Mipmap level.
rect - The section of the texture to copy. null indicates the data will be copied from the entire texture.
data - Array of data.
startIndex - Index of the first element to get.
elementCount - Number of elements to get.

SaveAsJpeg

public void SaveAsJpeg(java.io.OutputStream stream,
                       int width,
                       int height)
Saves texture data as a .jpg.

Parameters:
stream - Data stream number.
width - Image width.
height - Image height.

SaveAsPng

public void SaveAsPng(java.io.OutputStream stream,
                      int width,
                      int height)
Saves texture data as a .png.

Parameters:
stream - Data stream number.
width - Image width.
height - Image height.

SetData

public <T> void SetData(T[] data)
Sets 2D texture data. Reference page contains links to related conceptual articles.

Parameters:
data - Array of data.

SetData

public <T> void SetData(T[] data,
                        int startIndex,
                        int elementCount)
Sets 2D texture data, specifying a start index, and number of elements.

Parameters:
data - Array of data.
startIndex - Index of the first element to set.
elementCount - Number of elements to set.

SetData

public <T> void SetData(int level,
                        Rectangle rect,
                        T[] data,
                        int startIndex,
                        int elementCount)
Sets 2D texture data, specifying a mipmap level, source rectangle, start index, and number of elements.

Parameters:
level - Mipmap level.
rect - A bounding box that defines the position and location (in pixels) of the data.
data - Array of data.
startIndex - Index of the first element to set.
elementCount - Number of elements to set.