locked
NEED HELP!How to load bitmap from file async using WIC?

    Question

  • I'm using create_async to load bitmap.

    This works fine under release mode, but failed in debug mode.

    Following is my code

    Concurrency::create_async([&]()
    {
           mBackGround = new YHMSprite(mDeviceResources, L"Textures\\Menu\\background.png");
    });
    
    YHMSprite::YHMSprite(shared_ptr<DX::DeviceResources> &deviceResources, LPCWSTR fileName)
    {
    	mDeviceResources = deviceResources;
    	ComPtr<IWICBitmapDecoder> wicBitmapDecoder;
    	mDeviceResources->GetWicImagingFactory()->CreateDecoderFromFilename(fileName, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &wicBitmapDecoder);
    	ComPtr<IWICBitmapFrameDecode> wicBitmapFrame;
    	wicBitmapDecoder->GetFrame(0, &wicBitmapFrame);
    	ComPtr<IWICFormatConverter> wicFormatConverter;
    	mDeviceResources->GetWicImagingFactory()->CreateFormatConverter(&wicFormatConverter);
    	wicFormatConverter->Initialize(wicBitmapFrame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom);
    	double DpiX = 96.0f, DpiY = 96.0f;
    	wicFormatConverter->GetResolution(&DpiX, &DpiY);
    	mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap);
    	mBitmapSize = mBitmap->GetSize();
    	mDeviceResources->GetD2DFactory()->CreateDrawingStateBlock(&mStateBlock);
    }

    And triggered in this line 

    mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap);

    Any help will be appreciated!Thanks!

    Saturday, January 25, 2014 5:18 AM

Answers

All replies

  • Hello,

    What is the HRESULT that you are seeing when you get the failure?

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, January 28, 2014 12:29 AM
    Moderator
  • I have solved my problem using different way to loading resources.

    Thank you any way.

    Wednesday, January 29, 2014 8:07 AM