GDI+:如何用红色像素替换黑色像素?

GDI+: How to replace black pixels with red pixels?

我有一张黑白图像,想用红色像素替换黑色像素。我试过了

Gdiplus::Graphics* g = Gdiplus::Graphics::FromImage(filename);

Gdiplus::ImageAttributes ia;

Gdiplus::ColorMatrix m = { 
    0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
    0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
    1.0f, 0.0f, 0.0f, 0.0f, 1.0f
};

ia.SetColorMatrix(&m);

g->DrawImage(org, r, 0, 0, org->GetWidth(), org->GetHeight(), Gdiplus::UnitPixel, &ia);

但它会使整个位图变红。

不要使用矩阵来执行此转换。您的矩阵将始终输出以下向量:
[1.0 0.0 0.0 currentAlpha 1.0]
这就是为什么你的图像是红色的。
访问 https://msdn.microsoft.com/en-us/library/ms533875%28v=vs.85%29.aspx
改用这个

ImageAttributes ia;

ColorMap blackToRed;

blackToRed.oldColor = Color(255, 0, 0, 0);  // black

blackToRed.newColor = Color(255, 255, 0, 0);// red

ia.SetRemapTable(1, &blackToRed);