Exemplo n.º 1
0
 /// <summary>
 /// Creates a <see cref="SharpDX.Direct3D11.Texture2D"/> from a WIC <see cref="SharpDX.WIC.BitmapSource"/>
 /// </summary>
 /// <param name="device">The Direct3D11 device</param>
 /// <param name="bitmapSource">The WIC bitmap source</param>
 /// <returns>A Texture2D</returns>
 public static SharpDX.Direct3D11.Texture2D CreateTexture2DFromBitmap(SharpDX.Direct3D11.Device device, SharpDX.WIC.BitmapSource bitmapSource)
 {
     // Allocate DataStream to receive the WIC image pixels
     int stride = bitmapSource.Size.Width * 4;
     using (var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true))
     {
         // Copy the content of the WIC to the buffer
         bitmapSource.CopyPixels(stride, buffer);
         return new SharpDX.Direct3D11.Texture2D(device, new SharpDX.Direct3D11.Texture2DDescription()
         {
             Width = bitmapSource.Size.Width,
             Height = bitmapSource.Size.Height,
             ArraySize = 1,
             BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource,
             Usage = SharpDX.Direct3D11.ResourceUsage.Immutable,
             CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
             Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
             MipLevels = 1,
             OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
             SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
         }, new SharpDX.DataRectangle(buffer.DataPointer, stride));
     }
 }
Exemplo n.º 2
0
 public static Texture2D CreateTexture2DFromBitmap(Device device, SharpDX.WIC.BitmapSource bitmapSource, Texture2DDescription texDesc)
 {
     // Allocate DataStream to receive the WIC image pixels
     int stride = bitmapSource.Size.Width * 4;
     using(var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true))
     {
         // Copy the content of the WIC to the buffer
         bitmapSource.CopyPixels(stride, buffer);
         return new Texture2D(device, texDesc, new SharpDX.DataRectangle(buffer.DataPointer, stride));
     }
 }