0
votes

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 ..

1

1 Answers

0
votes

Your CopyFromMemory call is copying a three byte color bitmap into a four byte color bitmap. CopyFromMemory does not do format conversion, meaning the format of the source and destination bitmaps must match exactly. In addition, DXGI does not support a three byte color format, so the source bitmap must be modified to four bytes per pixel, even if the fourth is not used. If you cannot change the format of the source bitmap to match the Direct2D bitmap, then you will need to write a conversion function that will expand the bitmap elements to four bytes.