TextureLoader.FromFile(Device,String) Method (Microsoft.DirectX.Direct3D)

Creates a texture from a file.

Definition

Visual Basic Public Shared Function FromFile( _
    ByVal device As Device, _
    ByVal srcFile As String _
) As Texture
C# public static Texture FromFile(
    Device device,
    string srcFile
);
C++ public:
static TextureFromFile(
    Devicedevice,
    StringLeave SitesrcFile
);
JScript public static function FromFile(
    device : Device,
    srcFile : String
) : Texture;

Parameters

device Microsoft.DirectX.Direct3D.Device
A Device object that represents the device to associate with the texture.
srcFile System.String
String that specifies the file name.

Return Value

Microsoft.DirectX.Direct3D.Texture
A Texture object that represents the created texture object.

Remarks

This method supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga.

Cube textures differ from other surfaces in that they are collections of surfaces. To call Device.SetRenderTarget with a cube texture, select an individual face using CubeTexture.GetCubeMapSurface and pass the resulting surface to Device.SetRenderTarget.

To get the best performance when using FromFile, consider the following:

  • Doing image scaling and format conversion at load time can be slow. Store images in the format and resolution in which they will be used. If the target hardware requires power of 2 dimensions, use it to create and store images.
  • For mipmap image creation at load time, filter using Box. A box filter is much faster than other filter types such as Triangle.
  • Consider using DDS files. Since they can be used to represent any Microsoft DirectX texture format, they are easily read by this method. Also, they can store mipmaps, which means that any mipmap-generation algorithms can be used to author the images.

Exceptions

InvalidCallException

The method call is invalid. For example, a method's parameter might contain an invalid value.

InvalidDataException

The data is invalid.

NotAvailableException

This device does not support the queried technique.

OutOfVideoMemoryException

Microsoft Direct3D does not have enough display memory to perform the operation.

OutOfMemoryExceptionLeave Site

Direct3D could not allocate sufficient memory to complete the call.

See Also