为PNG图像提供彩色背景的合适蜡是什么?如下例所示:
具有不同级别的不透明度和透明背景的PNG图片:
问题是要使用指定的颜色从旧的图像中复制新的图像。
第二部分是如何向PNG图像添加颜色叠加层。也许用新颜色替换白色。
答案 0 :(得分:0)
如果我错了,请纠正我..但是使用灰度图像代替带有Alpha通道的PNG可能是一种可能性
Bitmap colorBitmap(Color forGroundColor, Color backGroundColor, Bitmap bmpGrayScale)
{
Size size = bmpGrayScale.Size;
Bitmap applyForgroundColor= new Bitmap(size.Width, size.Height);
Rectangle rect1 = new Rectangle(Point.Empty, bmpGrayScale.Size);
using (Graphics G1 = Graphics.FromImage(applyForgroundColor) )
{
G1.Clear(forGroundColor);
G1.DrawImageUnscaledAndClipped(applyForgroundColor, rect1);
}
for (int y = 0; y < size.Height; y++)
for (int x = 0; x < size.Width; x++)
{
Color c1 = applyForgroundColor.GetPixel(x, y);
Color c2 = bmpGrayScale.GetPixel(x, y);
applyForgroundColor.SetPixel(x, y, Color.FromArgb((int)(255 * c2.GetBrightness()), c1 ) );
}
Bitmap applyBackgroundColor= new Bitmap(size.Width, size.Height);
Rectangle rect2 = new Rectangle(Point.Empty, bmpGrayScale.Size);
using (Graphics G2 = Graphics.FromImage(applyBackgroundColor) )
{
G2.Clear(backGroundColor);
G2.DrawImageUnscaledAndClipped(applyForgroundColor, rect2);
}
return applyBackgroundColor;
}