OpenCV Mat to Id2d1Bitmap

asked 2018-07-19 01:30:15 -0500

Vivek1may gravatar image

updated 2018-07-19 01:34:31 -0500

I have to render opencv Mat to using DirectX 11.

D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1(
            D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
            D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE),
            96,
            96
        );
D2D1_SIZE_U s = D2D1::SizeU(640, 480);
hr = m_d2DeviceContext->CreateBitmap(s, bitmapProp, &m_streamBitmap);

I have to copy opencv matrix to m_streamBitmap. pImage is a color image with 3 channels.

m_streamBitmap->CopyFromMemory(NULL, reinterpret_cast<BYTE*>(pImage.data),pImage.cols()*3);

This gives distorted image as result. Can anyone guide me with this.

Thanks in advance .

edit retag flag offensive close merge delete

Comments

DXGI_FORMAT_B8G8R8A8_UNORM <-- that looks, like you need to convert to BGRA first, and later use: pImage.cols()*4); for stride

berak gravatar imageberak ( 2018-07-19 01:42:47 -0500 )edit
berak gravatar imageberak ( 2018-07-19 01:46:18 -0500 )edit