转换透明的PNG的颜色单色 [英] Convert transparent png in color to single color

查看:239
本文介绍了转换透明的PNG的颜色单色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与位图C#工作,并想知道如何彩色png图片转换成只有一种颜色。我希望所有的图像中的可见的颜色变成白色。这是透明的部位应保持透明。我要显示这些agains灰色背景。

I am working with Bitmap C# and wondering how to convert a color png image to only one color. I want all the visible colors in the image to become white. The parts that are transparent should remain transparent. I am going to display these agains a grey background.

推荐答案

其他的答案是有益的,让我去,非常感谢。我不能让他们的工作,虽然,不知道为什么。但我也发现,我想保持像素的原始alpha值,使边缘光滑。这是我想出了。

The other answers was helpful and got me going, thanks a lot. I couldn't make them work though, not sure why. But I also found out that I wanted to keep the original alpha value of the pixels, rendering the edges smooth. This is what I came up with.

for (int x = 0; x < bitmap.Width; x++)
{
    for (int y = 0; y < bitmap.Height; y++)
    {
        Color bitColor = bitmap.GetPixel(x, y);
        //Sets all the pixels to white but with the original alpha value
        bitmap.SetPixel(x, y, Color.FromArgb(bitColor.A, 255, 255, 255));
    }
}

下面是放大了几十倍(原顶部)结果的屏幕转储:

Here is a screen dump of the result magnified a few times (original on top):

这篇关于转换透明的PNG的颜色单色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆