BitmapSourceExtensions.CopyTo Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Include Protected Members
Include Inherited Members
Include Silverlight Members
Include Silverlight for Windows Phone Members
Include XNA Framework Members
Copies a bitmap image to a texture.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
Overload List
Name | Description | |
---|---|---|
CopyTo(BitmapSource, Texture2D) | Copies a bitmap image to a texture. | |
CopyTo(BitmapSource, TextureCube, CubeMapFace) | Copies a bitmap image to a cube map face. | |
CopyTo(BitmapSource, Texture2D, Int32, Nullable<Rectangle>, Int32, Int32) | Copies a sub-region of bitmap to a sub-region of the texture. | |
CopyTo(BitmapSource, TextureCube, CubeMapFace, Int32, Nullable<Rectangle>, Int32, Int32) | Copies a sub-region of bitmap to a sub-region of the cube map face. |
Top
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);