[英]SharpDX Texture2D to Bitmap
I have a problem with using SharpDX. 我在使用SharpDX时遇到问题。 I convert a Bitmap, lock the bits with the lockBits method and then create a DataStream and build a Texture2D from it. 我将转换一个位图,使用lockBits方法锁定位,然后创建一个DataStream并从中构建Texture2D。 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. 我想将Texture2D转换回位图。 There is a method called Texture2D.ToStream(size, texture2D, stream) but when I try this only an error occurs. 有一个称为Texture2D.ToStream(size,texture2D,stream)的方法,但是当我尝试这样做时,只会发生错误。 Can anyone help me with this issue? 谁能帮我解决这个问题? A conversion to an Image or WriteableBitmap would be also okay. 转换为Image或WriteableBitmap也可以。
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 我的DirectX版本是11.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.