gpt4 book ai didi

c# - 从 Texture2D 获取 SharpDX.Direct2D1.Bitmap

转载 作者:太空宇宙 更新时间:2023-11-03 10:44:14 25 4
gpt4 key购买 nike

我正在尝试创建一个屏幕外位图以在其上绘制,然后使用 Direct2D1.RenderTarget.DrawBitmap 绘制它。所以我创建了 Texture2D 并从中获取位图。但是我收到错误

[D2DERR_UNSUPPORTED_PIXEL_FORMAT/UnsupportedPixelFormat] 

在最后一串代码中。请帮助我理解,我在这里做错了什么?

    m_texture = new Texture2D(
context.Device,
new Texture2DDescription() {
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = Format.B8G8R8A8_UNorm,
Height = bitmapSize.Height,
Width = bitmapSize.Width,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription() {
Count = 1,
Quality = 0
},
Usage = ResourceUsage.Default
}
);

m_surface = m_texture.QueryInterface<Surface>();

using (SharpDX.Direct2D1.Factory factory = new SharpDX.Direct2D1.Factory()) {
m_renderTarget = new RenderTarget(
factory,
m_surface,
new RenderTargetProperties() {
DpiX = 0.0f, // default dpi
DpiY = 0.0f, // default dpi
MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT,
Type = RenderTargetType.Hardware,
Usage = RenderTargetUsage.None,
PixelFormat = new SharpDX.Direct2D1.PixelFormat(
Format.Unknown,
AlphaMode.Premultiplied
)
}
);
}

m_bitmap = new SharpDX.Direct2D1.Bitmap(m_renderTarget, m_surface);

最佳答案

  public static SharpDX.Direct2D1.Bitmap GetBitmapFromSRV(SharpDX.Direct3D11.ShaderResourceView srv, RenderTarget renderTarger)
{
using (var texture = srv.ResourceAs<Texture2D>())
using (var surface = texture.QueryInterface<Surface>())
{
var bitmap = new SharpDX.Direct2D1.Bitmap(renderTarger, surface, new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat(
Format.R8G8B8A8_UNorm,
SharpDX.Direct2D1.AlphaMode.Premultiplied)));
return bitmap;
}
}

关于c# - 从 Texture2D 获取 SharpDX.Direct2D1.Bitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24107494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com