Search code examples
c#imagec#-3.0c#-4.0fade

Best way to fade in/out image


What is the best (least resource heavy) way to fade an image in and out every 20 seconds with a duration of 1 second, against a black background (screensaver), in C# ?

(an image about 350x130px).

I need this for a simple screensaver that's going to run on some low level computers (xp).

Right now I'm using this method against a pictureBox, but it is too slow:

    private Image Lighter(Image imgLight, int level, int nRed, int nGreen, int nBlue)
    {
        Graphics graphics = Graphics.FromImage(imgLight);
        int conversion = (5 * (level - 50));
        Pen pLight = new Pen(Color.FromArgb(conversion, nRed,
                             nGreen, nBlue), imgLight.Width * 2);
        graphics.DrawLine(pLight, -1, -1, imgLight.Width, imgLight.Height);
        graphics.Save();
        graphics.Dispose();
        return imgLight;
    }

Solution

  • You could probably use a Color Matrix like in this example on msdn

    http://msdn.microsoft.com/en-us/library/w177ax15%28VS.71%29.aspx