close

m_DrawTexture 是畫出來的材質

pTextureRead 讀圖用的材質

{
ID3D11Texture2D* pTextureRead;
D3D11_TEXTURE2D_DESC texDescCV;
ZeroMemory(&texDescCV, sizeof(texDescCV));
texDescCV.Width = mClientWidth;
texDescCV.Height = mClientHeight;
texDescCV.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texDescCV.MipLevels = 1;
texDescCV.ArraySize = 1;
texDescCV.SampleDesc.Quality = 0;
texDescCV.SampleDesc.Count = 1;
texDescCV.MiscFlags = 0;
texDescCV.Usage = D3D11_USAGE_STAGING;
texDescCV.BindFlags = 0;
texDescCV.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
float* nothingImages = new float[mClientWidth * mClientHeight * 4];
D3D11_SUBRESOURCE_DATA sSubDataCV;
sSubDataCV.SysMemPitch = (UINT)(mClientWidth * 4 * 4);
sSubDataCV.SysMemSlicePitch = (UINT)(mClientWidth * mClientHeight * 4 * 4);
sSubDataCV.pSysMem = nothingImages;
HR(m_d3dDevice->CreateTexture2D(&texDescCV, &sSubDataCV, &pTextureRead));
m_DeviceContext->CopyResource(pTextureRead, m_DrawTexture);
D3D11_MAPPED_SUBRESOURCE MappedResource;
float* pimg;
unsigned int subresource = D3D11CalcSubresource(0, 0, 0);
HR(m_DeviceContext->Map(pTextureRead, subresource, D3D11_MAP_READ, 0, &MappedResource));
pimg = (float*)MappedResource.pData;
cv::Mat simg;
simg.create(mClientHeight, mClientWidth, CV_8UC3);
simg = cv::Scalar(0);
int addoffset = (8 - (mClientWidth - (mClientWidth / 8 * 8))) % 8;

for (int j = 0; j < simg.cols; ++j)
{
for (int i = 0; i < simg.rows; ++i)
{
int offset = (i * (simg.cols + addoffset) + j) * 4;
cv::Vec3b& intensity = simg.at<cv::Vec3b>(i, j);
intensity[2] = pimg[offset ] * 255.0f;
intensity[1] = pimg[offset + 1] * 255.0f;
intensity[0] = pimg[offset + 2] * 255.0f;
}
}

cv::imshow("gimg", simg);
delete [] nothingImages;
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 讓地獄深紅的天亮 的頭像
    讓地獄深紅的天亮

    !壞人必需做好事!

    讓地獄深紅的天亮 發表在 痞客邦 留言(0) 人氣()