这是我的代码:
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
auto outBuffer_ = new char[1920 * 1080 * 4];
memset(outBuffer_, 0, 1920 * 1080 * 4);
auto outBuffer = new char[1920* 1080 * 4];
for (int i = 0; i < 1920 * 1080; i++){
outBuffer[0 + i * 4] = 255;//a
outBuffer[1 + i * 4] = 255;//r
outBuffer[2 + i * 4] = 0;//g
outBuffer[3 + i * 4] = 0;//b
}
auto pBitmap_A =new Gdiplus::Bitmap(static_cast<INT>(1920),
static_cast<INT>(1080), static_cast<INT>(4 * 1920), PixelFormat32bppARGB, reinterpret_cast<BYTE*>(outBuffer_));
auto pGrap = new Gdiplus::Graphics(pBitmap_A);
Gdiplus::Image* img = new Gdiplus::Bitmap(static_cast<INT>(1920), static_cast<INT>(1080),
static_cast<INT>(4 * 1920), PixelFormat32bppARGB, reinterpret_cast<BYTE*>(outBuffer));
Gdiplus::Status sts = pGrap->DrawImage(img, 0, 0, 1920, 1080);
FILE *p = fopen("f.rgb", "wb");
fwrite(outBuffer_, 1920 * 1080 * 4, 1, p);
我想要一个纯红色的图像。但文件全部为零。它只是一个黑色图像。
然而,当我想要一个纯蓝色的图像时
outBuffer[0 + i * 4] = 255;//a
outBuffer[1 + i * 4] = 0;//r
outBuffer[2 + i * 4] = 0;//g
outBuffer[3 + i * 4] = 255;//b
我得到了正常的蓝色图像。我的代码出了什么问题?