How to create ID2D1RenderTarget using IWICBitmapFrameDecode


  • Hi

         I am trying to create a RenderTarget using a frame. I am getting pixel format exception(The bitmap pixel format is unsupported. (Exception from HRESULT: 0x88982F80)). Not sure how to fix the issue. Here is my sample code. Note: I tried using a converter, the problem is quality, for some reason my saved picture is black and white (color is missing) and quality is pretty bad and not sure how to fix that. But look at my current code

            ComPtr<IWICBitmapFrameDecode> decoderFrame;
    	DX::ThrowIfFailed(decoder->GetFrame(0, &decoderFrame));
    	WICPixelFormatGUID formatGUID = GUID_WICPixelFormat32bppRGBA;
    	UINT width;
    	UINT height;
    	DX::ThrowIfFailed(decoderFrame->GetSize(&width, &height));
    	double dpiX;
    	double dpiY;
    	DX::ThrowIfFailed(decoderFrame->GetResolution(&dpiX, &dpiY));
            ComPtr<IWICBitmap> wicBitMap;
    	DX::ThrowIfFailed(this->m_wicFactory->CreateBitmapFromSource(decoderFrame.Get(), WICBitmapNoCache, &wicBitMap));
    	WICPixelFormatGUID bitMapPixFormat;
    	ComPtr<ID2D1RenderTarget> bitMapRenderTarget;
    	D2D1_RENDER_TARGET_PROPERTIES renderProp = D2D1::RenderTargetProperties();
    	//renderProp.dpiX = dpiX;
    	//renderProp.dpiY = dpiY;
    	//renderProp.pixelFormat = pixelFormat;
    	DX::ThrowIfFailed(this->m_d2dFactory->CreateWicBitmapRenderTarget(wicBitMap.Get(), &renderProp, &bitMapRenderTarget));

    • Edited by __PB Thursday, March 29, 2012 5:26 AM
    Thursday, March 29, 2012 5:10 AM

All replies

  • Hello,

    Would you please upload a whole project which can reproduce this issue to skydriver?

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 30, 2012 2:39 AM
  • I uploaded two files to SkyDrive, which are part of my WinRT extension. You can create one very easily using these two files (.h and .cpp). Here is the link to those files


    Look into function 'WaterMarkImage_1' that has the problem I mentioned above.

    There is another function 'WaterMarkImage' this function has memory leak issue, that I am dealing with on another thread. Due to memory leak with this function I tried a different way to resolve this issue, and ended up with the error.

    Once you have downloaded the code let me know, I will remove the share.


    • Edited by __PB Friday, March 30, 2012 4:58 AM
    Friday, March 30, 2012 4:55 AM