SurfaceLoader.FromSurface(Surface,Surface,PaletteEntry,Filter,Int32) Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Copy a Texture

Loads a surface from another surface with color conversion.


Visual Basic Public Shared Sub FromSurface( _
    ByVal destSurface As Surface, _
    ByVal srcSurface As Surface, _
    ByRef sourcePalette As PaletteEntry, _
    ByVal filter As Filter, _
    ByVal colorKey As Integer _
C# public static void FromSurface(
    Surface destSurface,
    Surface srcSurface,
    out PaletteEntry sourcePalette,
    Filter filter,
    int colorKey
C++ public:
static void FromSurface(
    [Out] PaletteEntrysourcePalette,
    Filter filter,
    int colorKey
JScript public static function FromSurface(
    destSurface : Surface,
    srcSurface : Surface,
    sourcePalette : PaletteEntry,
    filter : Filter,
    colorKey : int


destSurface Microsoft.DirectX.Direct3D.Surface
A Surface object that represents the destination surface.
srcSurface Microsoft.DirectX.Direct3D.Surface
A Surface object that represents the source surface.
sourcePalette Microsoft.DirectX.Direct3D.PaletteEntry[]
A PaletteEntry array that contains the source palette entries.
filter Microsoft.DirectX.Direct3D.Filter
One or more members of the Filter enumeration that control how the image is filtered.
colorKey System.Int32
Integer value that represents the color to replace with transparent black, or 0 to disable the colorKey. This value is always a 32-bit ARGB color, regardless of the source image format. alpha is significant and should usually be set to 0xFF for opaque color keys. Thus, for opaque black, the value is equal to 0xFF000000.


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.



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


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.

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,

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());