Share via


BitmapSourceExtensions.CopyTo Method (BitmapSource, Texture2D)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Copies a bitmap image to a texture.

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

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Sub CopyTo ( _
    bitmap As BitmapSource, _
    dest As Texture2D _
)
public static void CopyTo(
    this BitmapSource bitmap,
    Texture2D dest
)

Parameters

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.

Examples

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

Version Information

Silverlight

Supported in: 5

Platforms

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