C++ 如何创建32位红色纹理字节缓冲区
我想制作一个红色纹理图像缓冲区。有人能帮我把它弄对吗。我尝试了以下操作,但无法将缓冲区复制到ID3D11Texture2D中。我需要帮助:C++ 如何创建32位红色纹理字节缓冲区,c++,image-processing,gdi+,directx-11,C++,Image Processing,Gdi+,Directx 11,我想制作一个红色纹理图像缓冲区。有人能帮我把它弄对吗。我尝试了以下操作,但无法将缓冲区复制到ID3D11Texture2D中。我需要帮助: std::vector<BYTE> redTexture(w*h*4); const auto stride = w * 4; BYTE* buf = redTexture.data(); for (int i = 0; i < h; ++i) { const auto redValue = Gdiplus::Color::Red
std::vector<BYTE> redTexture(w*h*4);
const auto stride = w * 4;
BYTE* buf = redTexture.data();
for (int i = 0; i < h; ++i)
{
const auto redValue = Gdiplus::Color::Red;
memcpy(buf, &redValue, stride);
buf += stride;
}
std::矢量红色纹理(w*h*4);
常量自动步幅=w*4;
字节*buf=redTexture.data();
对于(int i=0;i
如果纹理的DXGI_格式是R8G8B8A8_UNORM,您可以这样做
std::vector<BYTE> redTexture(w*h*4);
for(int i=0; i<redTexture.size(); i++)
{
if(i%4==0)
{
redTexture[i]=255;
}
else if(i%4==3)
{
redTexture[i]=255;
}
else
{
redTexture[i]=0;
}
}
std::矢量红色纹理(w*h*4);
对于(int i=0;i谢谢@HMD。我已通过执行以下操作解决了此问题:
CImage m_cImage;
// create a test image
m_cImage.Create(w, -h, 8 * 4); // 8 bpp * 4 channel
auto hdc = m_cImage.GetDC();
Gdiplus::Graphics graphics(hdc);
// Create a SolidBrush object.
Gdiplus::SolidBrush redBrush(Gdiplus::Color::Red);
// Fill the rectangle.
Gdiplus::Status status = graphics.FillRectangle(&redBrush, 0, 0, w, h);
TRY_CONDITION(status == Gdiplus::Status::Ok);
....
// Then saved the m_cImage.GetBits() to bmp file using Gdiplus::Bitmap
// and my expected texture is found
你能不能只用Graphics.FillRectangle(常量画笔*,INT,INT,INT,INT)
?我需要一个纹理的红色像素字节缓冲区,我必须将其复制到ID3D11Texture2D中。还有其他简单的创建方法吗?我的目标纹理是DXGI_FORMAT_R32_,尽管找到了解决方案。如果有人发布不需要Gdiplus的解决方案,我将不胜感激。