1

正如我在标题中提到的,您知道如何水平/垂直翻转 ID3D10Texture2D 对象吗?

我使用此代码截取屏幕截图并将其保存到文件中。

ID3D10Resource *backbufferRes;
renderTargetView->GetResource(&backbufferRes);
ID3D10Texture2D *mRenderedTexture;

// Create our texture
D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = 0;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.Width = 640;  // must be same as backbuffer
texDesc.Height = 480; // must be same as backbuffer
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D10_USAGE_DEFAULT;

d3d10Device->CreateTexture2D(&texDesc, 0, &mRenderedTexture); 

d3d10Device->CopyResource(mRenderedTexture, backbufferRes);

D3DX10FilterTexture(mRenderedTexture, 0, D3DX10_FILTER_MIRROR_U);

D3DX10SaveTextureToFile(mRenderedTexture, D3DX10_IFF_PNG, L"test.png");

D3DX10FilterTexture(mRenderedTexture, 0, D3DX10_FILTER_MIRROR_U); 线条不反映我的纹理。有什么建议么 ?

4

1 回答 1

0

在您的着色器中执行 1-u 水平翻转或 1-v 垂直翻转。

编辑:如果您实际上没有进行任何渲染,那么有更好的方法来进行图像处理。但是,如果您想手动执行此操作,则必须使用地图并自己翻转数据。

你可以这样做(代码未经测试,所以请原谅任何编译错误):

D3D10Resource *backbufferRes;
renderTargetView->GetResource(&backbufferRes);
ID3D10Texture2D *mRenderedTexture;

// Create our texture
D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = 0;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.Width = 640;  // must be same as backbuffer
texDesc.Height = 480; // must be same as backbuffer
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Usage = D3D10_USAGE_DEFAULT;

d3d10Device->CreateTexture2D(&texDesc, 0, &mRenderedTexture); 

d3d10Device->CopyResource(mRenderedTexture, backbufferRes);

D3D10_MAPPED_TEXTURE2D d3d10MT = { 0 };
mRenderedTexture->Map( 0, D3D10_MAP_READ_WRITE, 0, &d3d10MT );

unsigned int* pPix = (unsigned int)d3d10MT.pData;

int rows    = 0;
int rowsMax = height;
while( rows < rowsMax )
{
    unsigned int* pRowStart = pPix + (rows * width);
    unsigned int* pRowEnd   = pRowStart + width;
    std::reverse( pRowStart, pRowEnd );
    rows++;
}

mRenderedTexture->Unmap();

D3DX10SaveTextureToFile(mRenderedTexture, D3DX10_IFF_PNG, L"test.png");

从文档顺便说一句:

D3DX10_FILTER_MIRROR_U u 轴上纹理边缘的像素应该被镜像,而不是包裹。

因此,当您过滤图像时,仅计算边缘周围的像素。

于 2013-09-05T08:25:45.930 回答