Export (0) Print
Expand All

BitmapSourceExtensions.CopyTo Method (BitmapSource, Texture2D)

Copies a bitmap image to a texture.

Namespace:  System.Windows.Media.Imaging
Assembly:  System.Windows.Xna (in System.Windows.Xna.dll)

public static void CopyTo(
	this BitmapSource bitmap,
	Texture2D dest
)

Parameters

bitmap
Type: System.Windows.Media.Imaging.BitmapSource
The bitmap image object.
dest
Type: Microsoft.Xna.Framework.Graphics.Texture2D
The texture.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type BitmapSource. When you use instance method syntax to call this method, omit the first parameter.

The following example shows how to use the CopyTo method on the BitmapSource class to convert a PNG image into a Texture. The PNG image is stored as a resource. CubeSample is the name of the project and SLXNA.png is the name of the image.

// Load image
Stream imageStream = Application.GetResourceStream(
    new Uri(@"CubeSample;component/SLXNA.png", UriKind.Relative)).Stream;

BitmapImage image = new BitmapImage();
image.SetSource(imageStream);

// Create texture
Texture2D texture = new Texture2D(
                          resourceDevice, 
                          image.PixelWidth, 
                          image.PixelHeight,
                          false, 
                          SurfaceFormat.Color);

// Copy image to texture
image.CopyTo(texture);

Silverlight

Supported in: 5

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

Show:
© 2014 Microsoft