WIC Direct2D CreateBitmapFromMemory: limitations on width and height?

拥有回忆 提交于 2019-12-11 02:56:36

问题


CreateBitmapFromMemory executes successfully when _nWidth is equal to or less than 644. If the value exceeds this value, the HRESULT value is -2003292276

Do limits exist on the width and height?

#include <d2d1.h>
#include <d2d1helper.h>

#include <wincodecsdk.h> // Use this for WIC Direct2D functions


void test() 
{
    IWICImagingFactory     *m_pIWICFactory;   
    ID2D1Factory           *m_pD2DFactory;
    IWICBitmap             *m_pEmbeddedBitmap;
    ID2D1Bitmap            *m_pD2DBitmap;

    unsigned char *pImageBuffer = new unsigned char[1024*1024];

    HRESULT hr = S_OK;

    int _nHeight = 300;
    int _nWidth =  644;

If nWidth exceeds 644, CreateBitmapFromMemory returns an Error.

    //_nWidth =  648;


    if (m_pIWICFactory == 0 )
    {
        hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

        // Create WIC factory
        hr = CoCreateInstance(
            CLSID_WICImagingFactory,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_PPV_ARGS(&m_pIWICFactory)
            );

        if (SUCCEEDED(hr))
        {
            // Create D2D factory
            hr = D2D1CreateFactory( D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory );
        }
    }

     hr = m_pIWICFactory->CreateBitmapFromMemory(
        _nHeight,   // height
        _nWidth,  // width
        GUID_WICPixelFormat24bppRGB, // pixel format of the NEW bitmap
        _nWidth*3,  // calculated from width and bpp information
        1024*1024, // height x width
        pImageBuffer, // name of the .c array
        &m_pEmbeddedBitmap  // pointer to pointer to whatever an IWICBitmap is.
        ); 

    if (!SUCCEEDED(hr)) {
        char *buffer = "Error in CreateBitmapFromMemory\n";
    }
}

回答1:


Error code is 0x88982F8C WINCODEC_ERR_INSUFFICIENTBUFFER and the reason is now obvious?

The first parameter is width, and the second is height. You have them in wrong order. All in all you provide incorrect arguments resulting in bad buffer.




回答2:


Are you sure you passed in the correct pixelFormat for function CreateBitmapFromMemory? you hard code it to GUID_WICPixelFormat24bppRGB, I think this is the root cause, you should make sure this format same as the format with the source bitmap which you are copy the data from. try use the GetPixelFormat function to get the correct format instead of hard code.




回答3:


There is an upper limit on the dimensions of images on the GPU.

Call GetMaximumBitmapSize on the render target. http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k(GetMaximumBitmapSize);k(DevLang-C%2B%2B);k(TargetOS-Windows)&rd=true

What you get back is the max pixels of either vertical or horiz. For larger images you'd have to load them into a software render target such as a bitmap render target and then render what you want from that.



来源:https://stackoverflow.com/questions/12907455/wic-direct2d-createbitmapfrommemory-limitations-on-width-and-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!