Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将彩色背景添加到PNG或将彩色覆盖添加到图像?_C#_Image_Uwp_Png - Fatal编程技术网

C# 如何将彩色背景添加到PNG或将彩色覆盖添加到图像?

C# 如何将彩色背景添加到PNG或将彩色覆盖添加到图像?,c#,image,uwp,png,C#,Image,Uwp,Png,为PNG图像提供彩色背景的合适蜡是什么。如下例所示: 具有不同不透明度和透明背景的PNG图像: 应用背景色的PNG图像: 问题是用指定的颜色从旧图像复制新图像 第二部分是如何向PNG图像添加颜色覆盖。也许用新颜色替换白色 这就是我的例子: 这就是我想得到的PNG示例: 如果我错了,请纠正我。。但这可能会使用灰度图像,而不是带有alpha通道的PNG Bitmap colorBitmap(Color forGroundColor, Color backGroundColor, Bitmap

为PNG图像提供彩色背景的合适蜡是什么。如下例所示:
具有不同不透明度和透明背景的PNG图像:

应用背景色的PNG图像:

问题是用指定的颜色从旧图像复制新图像

第二部分是如何向PNG图像添加颜色覆盖。也许用新颜色替换白色

这就是我的例子:

这就是我想得到的PNG示例:
如果我错了,请纠正我。。但这可能会使用灰度图像,而不是带有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;
}
位图颜色位图(彩色背景色、彩色背景色、位图bmpGrayScale)
{
尺寸=bmpGrayScale.Size;
位图applyForgroundColor=新位图(size.Width、size.Height);
矩形rect1=新矩形(Point.Empty,bmpGrayScale.Size);
使用(Graphics G1=Graphics.FromImage(applyForgroundColor))
{
G1.透明(彩色);
G1.DrawImageUnscaled和Clipped(applyForgroundColor,rect1);
}
对于(int y=0;y
对于GDI+请参见-对于第二个问题,请查看颜色矩阵。因此,我一直在自学。如果我可以问一下,
颜色目标
用类似于(#4286f4)的值表示?还是应该是RGB?你能给我一个值的例子吗?最好使用Color.FromArgb创建一个控制alpha和3RGB通道的颜色。