locked
E_INVALIDARG - CreateBitmapFromWicBitmap RRS feed

  • Question

  • Hi, is it a bug or I do something wrong ?

    ID2D1Bitmap1* pNewBitmap = NULL;

    D2D1_BITMAP_PROPERTIES1 properties = { };
    properties.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
    properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
    properties.dpiX = 96.0f;
    properties.dpiY = 96.0f;
    properties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
    properties.colorContext = NULL;

    // It's not the ID2D1RenderTarget method it's the ID2D1DeviceContext overload.
    HRESULT hr = pDeviceContext->CreateBitmapFromWicBitmap(
        pBitmap, &properties, &pNewBitmap );

    if ( FAILED( hr ) ) // E_INVALIDARG !??
    {
        SAFE_RELEASE( pNewBitmap );
    }
    Monday, February 6, 2012 2:06 PM

All replies

  • You don't give any details about the original bitmap so we can't do more than guess, but it sounds like the format of the WIC bitmap isn't matching up. The other arguments look like they should be valid.

    --Rob

    Monday, February 6, 2012 11:17 PM
    Moderator
  • I am getting the same error with an empty WIC premultiplied BGRA bitmap.

    HRESULT hr = S_OK;
    IWICBitmap* pWICBitmap = NULL;
    ID2D1Bitmap1* pD2DBitmap = NULL;

    // An useless empty bitmap, it's just for testing..
    hr = g_pWICFactory->CreateBitmap(
        1920,
        1080,
        GUID_WICPixelFormat32bppPBGRA,
        WICBitmapCacheOnLoad,
        &pWICBitmap );

    if ( SUCCEEDED( hr ) )
    {
        D2D1_BITMAP_PROPERTIES1 properties = { };
        properties.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
        properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
        properties.dpiX = 96.0f;
        properties.dpiY = 96.0f;
        properties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
        properties.colorContext = NULL;

        hr = pDeviceContext->CreateBitmapFromWicBitmap(
            pWICBitmap,
            &properties,
            &pD2DBitmap );

        if ( FAILED( hr ) ) // E_INVALIDARG !!
        {
            SAFE_RELEASE( pD2DBitmap );
        }
    }

    SAFE_RELEASE( pWICBitmap );

    ---

    Everything works fine with this method :

    //
    // Creates a bitmap with extended bitmap properties, potentially from a block of
    // memory.
    //
    STDMETHOD(CreateBitmap)(
        D2D1_SIZE_U size,
        _In_reads_bytes_opt_(size.height * pitch) CONST void *sourceData,
        UINT32 pitch,
        _In_ CONST D2D1_BITMAP_PROPERTIES1 *bitmapProperties,
        _Outptr_ ID2D1Bitmap1 **bitmap
        ) PURE;

    Tuesday, February 7, 2012 12:49 AM
  • Thanks for the sample code. I'll let you know once I've finished looking into this.

    --Rob

    Wednesday, February 8, 2012 3:09 AM
    Moderator