C# png如何保持alpha通道但更改背景颜色
我有一个带有alpha通道的png图像,对于我们的一个不支持alpha的工具,我需要编辑图像,这样每个透明的像素都有一个特定的颜色,但保持alpha,这样png仍然适用于所有支持alpha的工具 这是我到目前为止的代码,但它不起作用,有人能帮忙吗?图片是我的源png,我选择红色作为颜色 谢谢C# png如何保持alpha通道但更改背景颜色,c#,c#-4.0,png,png-transparency,C#,C# 4.0,Png,Png Transparency,我有一个带有alpha通道的png图像,对于我们的一个不支持alpha的工具,我需要编辑图像,这样每个透明的像素都有一个特定的颜色,但保持alpha,这样png仍然适用于所有支持alpha的工具 这是我到目前为止的代码,但它不起作用,有人能帮忙吗?图片是我的源png,我选择红色作为颜色 谢谢 using (Bitmap ImageAttachedConverted = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging
using (Bitmap ImageAttachedConverted = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
using (Graphics GraphicsPicture = Graphics.FromImage(ImageAttachedConverted))
{
GraphicsPicture.InterpolationMode = InterpolationMode.HighQualityBicubic;
GraphicsPicture.CompositingQuality = CompositingQuality.HighQuality;
//GraphicsPicture.Clear(Color.Red);
//GraphicsPicture.DrawImage(
// Picture,
// new Rectangle(0, 0, ImageAttachedConverted.Width, ImageAttachedConverted.Height),
// new Rectangle(0, 0, Picture.Width, Picture.Height),
// GraphicsUnit.Pixel);
// 2nd method pixel bypixel
Bitmap img = Picture as Bitmap;
for (int y = 0; y < ImageAttachedConverted.Height; y++)
{
for (int x = 0; x < ImageAttachedConverted.Width; x++)
{
//Get Colours at the pixel point
Color col1 = img.GetPixel(x, y);
Color temp = Color.FromArgb(
0,
255,
0,
0);
if (col1.A < 100)
ImageAttachedConverted.SetPixel(x, y, temp);
else ImageAttachedConverted.SetPixel(x, y, col1);
}
}
Color temp2 = Color.FromArgb(
0,
255,
0,
0);
//ImageAttachedConverted.MakeTransparent(temp2);
}
ImageAttachedConverted.Save(Destination.FullName, ImageFormat.Png);
}
使用(位图ImageAttachedConverted=新位图(Picture.Width、Picture.Height、System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
使用(Graphics GraphicsPicture=Graphics.FromImage(ImageAttachedConverted))
{
GraphicsPicture.InterpolationMode=InterpolationMode.HighQualityBicubic;
GraphicsPicture.CompositingQuality=CompositingQuality.HighQuality;
//图形结构。清晰(颜色。红色);
//GraphicsPicture.DrawImage(
//图片,
//新矩形(0,0,ImageAttachedConverted.Width,ImageAttachedConverted.Height),
//新矩形(0,0,图片.宽度,图片.高度),
//图形(像素);
//第二种方法逐像素
位图img=作为位图的图片;
对于(int y=0;y