我目前正在使用SharpDX.Direct2D1制作2D应用程序。

这是我的2D deviceContext正常运行的设置。

m_swapchaindesc = New SwapChainDescription()
    With m_swapchaindesc
        .BufferCount = 2
        .ModeDescription =
            New ModeDescription(control.Width, control.Height,
                                New Rational(60, 1), Format.R8G8B8A8_UNorm)
        .IsWindowed = True
        .OutputHandle = control.Handle
        .SampleDescription = New SampleDescription(1, 0)
        .SwapEffect = SwapEffect.Discard
        .Usage = Usage.RenderTargetOutput
    End With

    SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport Or DeviceCreationFlags.Debug, m_swapchaindesc, m_device, m_swapChain)

    Dim dxgiDevice As SharpDX.DXGI.Device = m_device.QueryInterface(Of SharpDX.DXGI.Device)()

    m_2dDevice = New SharpDX.Direct2D1.Device(dxgiDevice)
    m_d2dContext = New SharpDX.Direct2D1.DeviceContext(m_2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None)

    m_properties = New BitmapProperties(New SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 96, 96)

    m_backBuffer = m_swapChain.GetBackBuffer(Of Surface)(0)

    m_2dTarget = New SharpDX.Direct2D1.Bitmap(m_d2dContext, m_backBuffer, m_properties)
    m_d2dContext.Target = m_2dTarget


我的问题:我想在我的deviceContext上绘制8bpp位图灰度,这意味着我不需要每个像素32bits占用大量内存。我希望它仅8位用于存储目的。我这样做的问题是设置我的BitmapProperties,只有一个Format.R8_UnormFormat.A8_Unorm看起来很有趣,因为我猜他们只有8bpp。但是,当我使用这种格式并尝试实例化SharpDX.Direct2D1.Bitmap时,它返回一条错误消息,提示WRONGPIXELFORMAT。

我意识到在创建位图时,只有Format.R8G8B8A8_Unorm似乎起作用,而我不需要。

你们有没有在SharpDX上处理过8bpp灰度位图?

最佳答案

您不能将8BPP位图与SharpDX(DirectX)一起使用。 DirectX不支持此格式。为了能够显示灰度图像,您必须将rgb的所有值都设置为相同的值,或者对图像应用着色器以将所有颜色转换为灰色。

关于c# - SharpDX.Direct2D1.Bitmap的灰度8BPP位图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44949390/

10-09 03:20