Share via


SurfaceLoader.FromSurface Method ()

How Do I...?

  • Copy a Texture

Loads a surface from another surface with color conversion.

Overload List

public static void FromSurface(Surface, out PaletteEntry, Rectangle, Surface, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Rectangle, Surface, out PaletteEntry, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Rectangle, Surface, out PaletteEntry, Rectangle, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Rectangle, Surface, Rectangle, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Surface, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Surface, out PaletteEntry, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Surface, out PaletteEntry, Rectangle, Filter, int);
public static void FromSurface(Surface, out PaletteEntry, Surface, Rectangle, Filter, int);
public static void FromSurface(Surface, Rectangle, Surface, Filter, int);
public static void FromSurface(Surface, Rectangle, Surface, out PaletteEntry, Filter, int);
public static void FromSurface(Surface, Rectangle, Surface, out PaletteEntry, Rectangle, Filter, int);
public static void FromSurface(Surface, Rectangle, Surface, Rectangle, Filter, int);
public static void FromSurface(Surface, Surface, Filter, int);
public static void FromSurface(Surface, Surface, out PaletteEntry, Filter, int);
public static void FromSurface(Surface, Surface, out PaletteEntry, Rectangle, Filter, int);
public static void FromSurface(Surface, Surface, Rectangle, Filter, int);

Remarks

Writing to a surface level other than zero does not cause the dirty rectangle to be updated. If SurfaceLoader.FromSurface is called and the surface is not already dirty (which is unlikely under normal usage scenarios), the application must explicitly call Texture.AddDirtyRect on the surface.

Exceptions

InvalidCallException

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

InvalidDataException

The data is invalid.

How Do I...?

Copy a Texture

This example demonstrates how to copy a texture.

A texture is loaded from a file and duplicated, and all of its AliceBlue color is replaced with transparent black. An area that is ten pixels square from the top right corner of the texture is copied.

In the following C# code example, device is assumed to be the rendering Device, and FlagColorsInverted.bmp is assumed to be in the current directory.

              [C#]
              
using Microsoft.DirectX.Direct3D;
using System.Drawing;

Surface s = null;
                
PaletteEntry[] pal = new PaletteEntry[256];

// Set up the surface for our surface loader.
s = device.CreateOffscreenPlainSurface(32, 32, Format.A8R8G8B8, Pool.Default);
    
Surface k = TextureLoader.FromFile(device,
                          "FlagColorsInverted.bmp").GetSurfaceLevel(0);

SurfaceLoader.FromSurface(s, out pal, new Rectangle(0,0,9,9), k, out pal,
               new Rectangle(0,0,9,9), Filter.Box, Color.AliceBlue.ToArgb());