Avatar of Rock_Lobster

asked on 

Change color/tint of transparent image with C#

I have found a method that will convert to gray scale but it turns the entire transparent area black instead of keeping the background transparent and I would also like to just change the color a little to differ from original image, not necessarily changing it to gray scale. So say I have an red apple with a  transparent background I would just like to change color where the apple is more green than red and keep the background transparent. Is that possible in c#?  
public Bitmap ConvertToGrayscale(Bitmap source)
            Bitmap bm = new Bitmap(source.Width, source.Height);
            for (int y = 0; y < bm.Height; y++)
                for (int x = 0; x < bm.Width; x++)
                    Color c = source.GetPixel(x, y);
                    int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
                    bm.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
            return bm;

Open in new window

.NET Programming

Avatar of undefined
Last Comment
Bob Learned

8/22/2022 - Mon