문제

I have a png image with an alpha channel, for one of our tool which does not support alpha I need to edit the image so that every pixel which is transparent gets a specific color but keeps the alpha so the png still works for all the tools who supports alpha.

Here's my code so far, but it doesn't work, anyone can help? Picture is my source png and I chose red as the color.

Thanks

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);
}

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top