ID2D1RenderTarget :: CreateBitmap返回0x88982F80 [英] ID2D1RenderTarget::CreateBitmap returns 0x88982F80

查看:434
本文介绍了ID2D1RenderTarget :: CreateBitmap返回0x88982F80的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从内存来源数据创建ID2D1Bitmp,但ID2D1RenderTarget :: CreateBitmap函数始终返回0x88982F80错误代码,即使没有源数据也是如此。  My代码是对Direct2D示例代码的简单修改:(VS 2008 @ Windows 7)

I was trying to create an ID2D1Bitmp from the in-memory source data, but the ID2D1RenderTarget::CreateBitmap function always returns 0x88982F80 error code, even with no source data. My code is a simple modification of the Direct2D sample code: (VS 2008 @ Windows 7)

HWND m_hWnd;
ID2D1Factory *m_pD2DFactory;
ID2D1HwndRenderTarget *m_pRenderTarget;
ID2D1SolidColorBrush *m_pBrush;
ID2D1Bitmap *m_pBitmap;

IDWriteFactory *m_pDWriteFactory;
IDWriteTextFormat *m_pTextFormat;

/// CreateDeviceIndependentResources
///
/// This method is used to create resources which are not bound
/// to any device. Their lifetime effectively extends for the
/// duration of the app.
///
HRESULT CreateDeviceIndependentResources()
{
  static const WCHAR msc_fontName[] = L"Verdana";
  static const FLOAT msc_fontSize = 50;
  HRESULT hr;

  // Create a Direct2D factory.
  hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);

  if (SUCCEEDED(hr))
  {      
    // Create a DirectWrite factory.
    hr = DWriteCreateFactory(
        DWRITE_FACTORY_TYPE_SHARED,
        __uuidof(m_pDWriteFactory),
        reinterpret_cast<IUnknown **>(&m_pDWriteFactory)
        );
  }
  if (SUCCEEDED(hr))
  {
    // Create a DirectWrite text format object.
    hr = m_pDWriteFactory->CreateTextFormat(
        msc_fontName,
        NULL,
        DWRITE_FONT_WEIGHT_NORMAL,
        DWRITE_FONT_STYLE_NORMAL,
        DWRITE_FONT_STRETCH_NORMAL,
        msc_fontSize,
        L"", //locale
        &m_pTextFormat
        );
  }
  if (SUCCEEDED(hr))
  {
    // Center the text horizontally and vertically.
    m_pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);

    m_pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
  }

  return hr;
}

/// CreateDeviceResources
///
/// This method creates resources which are bound to a particular
/// D3D device. It's all centralized here, in case the resources
/// need to be recreated in case of D3D device loss (eg. display
/// change, remoting, removal of video card, etc).
///
HRESULT CreateDeviceResources()
{
  HRESULT hr = S_OK;

  if (!m_pRenderTarget)
  {
    RECT rc;

    if(!m_hWnd)
      m_hWnd = ::GetDesktopWindow();

    GetClientRect(m_hWnd, &rc);

    D2D1_SIZE_U size = D2D1::SizeU(
      rc.right - rc.left,
      rc.bottom - rc.top
      );

    // Create a DC render target.
    D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
        D2D1_RENDER_TARGET_TYPE_DEFAULT,
        D2D1::PixelFormat(
            DXGI_FORMAT_B8G8R8A8_UNORM,
            D2D1_ALPHA_MODE_IGNORE),
        0,
        0,
        D2D1_RENDER_TARGET_USAGE_NONE,
        D2D1_FEATURE_LEVEL_DEFAULT
        );

    // Create a GDI render target
    //hr = m_pD2DFactory->CreateDCRenderTarget(&props, &m_pDCRT);

    // Create a Direct2D render target
    hr = m_pD2DFactory->CreateHwndRenderTarget(
      D2D1::RenderTargetProperties(),
      D2D1::HwndRenderTargetProperties(m_hWnd, size),
      &m_pRenderTarget
      );
    if (SUCCEEDED(hr))
    {
        // Create a black brush.
        hr = m_pRenderTarget->CreateSolidColorBrush(
            D2D1::ColorF(D2D1::ColorF::Black),
            &m_pBrush
            );

        // Create an uninitialized bitmap
        hr = m_pRenderTarget->CreateBitmap(       // <==================== Failed to create bitmap
          D2D1::SizeU(10, 10),
          D2D1::BitmapProperties(
          D2D1::PixelFormat(
          DXGI_FORMAT_B5G6R5_UNORM, 
          D2D1_ALPHA_MODE_IGNORE)
          ),
          &m_pBitmap
          );
    }
  }

  return hr;
}

/// DiscardDeviceResources
///
/// Discard device-specific resources which need to be recreated
/// when a D3D device is lost
///
void DiscardDeviceResources()
{
  SafeRelease(&m_pRenderTarget);
  SafeRelease(&m_pBrush);
  SafeRelease(&m_pBitmap);
}

推荐答案

这是wincodec.h中的WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT。试试32bppPBGR。

That is WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT in wincodec.h. Try 32bppPBGR.

Direct2D基于Direct3D,所以你可能想在forums.xna.com上试试Direct3D论坛。

Direct2D is based on Direct3D, so you may want to try the Direct3D forums on forums.xna.com.


这篇关于ID2D1RenderTarget :: CreateBitmap返回0x88982F80的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆