-2

I'm trying to save a ID2D1bitmap to a file according to this How to save ID2D1Bitmap to PNG file

Can this be done in windows 7? without any platform update?

I get an Unhandled exception. (Aceess violation reading) at :

if (SUCCEEDED(hr))
{
    hr = m_pWICFactory->CreateBitmap(
        sc_bitmapWidth,
        sc_bitmapHeight,
        GUID_WICPixelFormat32bppPBGRA,
        WICBitmapCacheOnLoad,
        &pWICBitmap
        );
}

I've declared m_pWICFactory & m_pDirect2dFactory as:

ID2D1Factory* m_pDirect2dFactory;
IWICImagingFactory *m_pWICFactory;

Can some one explain me the problem?

Community
  • 1
  • 1
user2557850
  • 119
  • 1
  • 3
  • 14

1 Answers1

1

I'm pretty sure that you've a null m_pWICFactory (because the post you've linked to doesn't contain that code). Did you initialize it first before usage? It is usually done with a member function like so and is called before other operations that require the factory is performed.

HRESULT CreateDeviceIndependentResources()
{
    HRESULT hr;

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

    if (SUCCEEDED(hr))
    {
        // Create a WIC factory.
        CoCreateInstance(
            CLSID_WICImagingFactory,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWICImagingFactory,
            reinterpret_cast<void **>(&m_pWICFactory)
            );
    }
    return hr;
}

Refer Using the Windows Imaging Component in MSDN for more information.

legends2k
  • 31,634
  • 25
  • 118
  • 222
  • The output Image is just empty with white color similar to the problem initially faced by this user [link] (http://stackoverflow.com/questions/11447489/how-to-save-id2d1bitmap-to-png-file) however I've debugged my code and unlike him hr = S_OK throughout. What seems to be the problem ? – user2557850 Jun 01 '14 at 20:05
  • Make sure you've a valid `pBitmap` which is created from the same ID2D1Factory object. – legends2k Jun 01 '14 at 20:40