locked
One problem about ID2D1Bitmap::CopyFromBitmap API RRS feed

  • Question

  • I tried to get pixels from D2D1Bitmap1 and I have read this discussion http://social.msdn.microsoft.com/Forums/en/winappswithnativecode/thread/c9426e4c-56a0-48b6-96d1-105e9e9e581e

    This is my code. 

    D2D1_BITMAP_PROPERTIES1 prop = D2D1::BitmapProperties1(
    		D2D1_BITMAP_OPTIONS_CPU_READ | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
    		D2D1::PixelFormat(
    		DXGI_FORMAT_B8G8R8A8_UNORM,
    		D2D1_ALPHA_MODE_PREMULTIPLIED
    		)
    		);
    
    	D2D1_SIZE_U pixelSize = m_d2dContext->GetPixelSize();
    	ComPtr<ID2D1Bitmap1> otherBmp;
    	DX::ThrowIfFailed(m_d2dContext->CreateBitmap(
    		pixelSize, 
    		nullptr,
    		pixelSize.width * 4,
    		&prop,
    		&otherBmp
    		)
    	);
    	
    	D2D1_RECT_U rect = {0, 0, m_sInputTextProp.iBackgroundWidth, m_sInputTextProp.iBackgroundHeight};
    	D2D1_POINT_2U point = {0, 0};
    	DX::ThrowIfFailed(otherBmp->CopyFromBitmap(&point, outputbitmap.Get(), &rect));  
    	
    	D2D1_MAP_OPTIONS options = D2D1_MAP_OPTIONS_READ;
    	D2D1_MAPPED_RECT mappedRect;
    	DX::ThrowIfFailed(otherBmp->Map(options, &mappedRect));
    	memcpy(pPixelData, mappedRect.bits, m_sInputTextProp.iBackgroundWidth * m_sInputTextProp.iBackgroundHeight * 4);
    	otherBmp->Unmap();


    This code can run successfully on Intel i5 IVB machine (integrated VGA) and get the correct pixels data.

    But I get corrupted pixels data on AMD HD 6850 or NVIDIA 450 GTS.

    I tried to use IWICImageEncoder to save it as a bitmap before I call CopyFromBitmap.

    And this bitmap is correct on 3 VGA cards.

    I don't know it's my code problem or does it have any possibility of VGA vendor's driver issue? 

    Thanks.




    Friday, November 2, 2012 9:25 AM

Answers

  • maybe mappedRect.pitch and pich of pPixelData is incorrected;

    use mappedRect.pitch

     

    Monday, November 12, 2012 12:31 PM
  • Hi Albert,

    I found it's real different between mappedRect.pitch and m_sInputTextProp.iBackgroundWidth 

    I modified it as 

    BYTE *pSrcData = mappedRect.bits;
    BYTE *pTarData = pPixelData;
    for(int i = 0; i < m_sInputTextProp.iOutputBackgroundHeight; i++)
    {
    	memcpy(pTarData,pSrcData,m_sInputTextProp.iOutputBackgroundWidth*4);
    	pTarData += m_sInputTextProp.iOutputBackgroundWidth *4;
    	pSrcData += mappedRect.pitch;
    }

    And it's fixed.

    Thank you very much.


    Wednesday, November 14, 2012 3:05 AM

All replies

  • maybe mappedRect.pitch and pich of pPixelData is incorrected;

    use mappedRect.pitch

     

    Monday, November 12, 2012 12:31 PM
  • Hi Albert,

    I found it's real different between mappedRect.pitch and m_sInputTextProp.iBackgroundWidth 

    I modified it as 

    BYTE *pSrcData = mappedRect.bits;
    BYTE *pTarData = pPixelData;
    for(int i = 0; i < m_sInputTextProp.iOutputBackgroundHeight; i++)
    {
    	memcpy(pTarData,pSrcData,m_sInputTextProp.iOutputBackgroundWidth*4);
    	pTarData += m_sInputTextProp.iOutputBackgroundWidth *4;
    	pSrcData += mappedRect.pitch;
    }

    And it's fixed.

    Thank you very much.


    Wednesday, November 14, 2012 3:05 AM