I have a problem with using SharpDX. I convert a Bitmap, lock the bits with the lockBits method and then create a DataStream and build a Texture2D from it. This seems to work quite well, no error occurs. Now I have the following problem. I want to convert the Texture2D back to a Bitmap. There is a method called Texture2D.ToStream(size, texture2D, stream) but when I try this only an error occurs. Can anyone help me with this issue? A conversion to an Image or WriteableBitmap would be also okay.
Asked
Active
Viewed 2,704 times
1
-
What directx version are you using? (10/11 or d2d) – mrvux Nov 03 '12 at 14:59
-
You can find the answer here: https://stackoverflow.com/questions/37099845/convert-slimdx-direct3d11-texture2d-to-net-bitmap/47072283#47072283 – Thomas Hoerhan Nov 25 '17 at 16:47
1 Answers
-1
I found a solution:
var inputTex2D = Texture2D.FromStream<Texture2D>(device, inputMemoryStream, (int)inputMemoryStream.Length, new ImageLoadInformation()
{
Depth = 1,
FirstMipLevel = 0,
MipLevels = 0,
Usage = ResourceUsage.Default,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Format = Format.R8G8B8A8_UNorm,
Filter = FilterFlags.None,
MipFilter = FilterFlags.None,
});
My DirectX Version is 11.0

Simon Rühle
- 229
- 3
- 12