Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ReflectionPicture

0.00/5 (No votes)
21 Feb 2007 1  
A Vista-Style control that shows an image and its gradient-opactity reflection.

Screenshot - screen.jpg

Introduction

This control tries to simulate the reflection of an image with lower opacity, like it appears in the above image. The control is very easy to use.

In order to create the reflection, the control calls the function SubActualizarReflejo, that creates the reflection image.

private void SubActualizarReflejo()
{
    try
    {
        actualizando = true;
        this.reflejo = null;

        Bitmap volteada = new Bitmap(imagen, ObtenerAreaImagen().Size);
        volteada.RotateFlip(RotateFlipType.RotateNoneFlipY);
        Bitmap reflejo = new Bitmap(volteada.Width, 
                         volteada.Height, PixelFormat.Format32bppArgb);

        for (int y = 0; y < volteada.Height; y++)
        {
            //Opacidad resultante para un pixel totalmente opaco
            int opacidad = (int)Math.Round(((double)255 / volteada.Height) * 
                                           (volteada.Height - y)) - indiceOpacidad;

            if (opacidad < 0) opacidad = 0;
            if (opacidad > 255) opacidad = 255;

            for (int x = 0; x < volteada.Width; x++)
            {
                Color color = volteada.GetPixel(x, y);
                if (color.A == 0)
                    continue;

                int opacidadPixel = 
                   (int)Math.Round((opacidad / (double)255) * color.A);
                reflejo.SetPixel(x, y, Color.FromArgb(opacidadPixel, 
                                 color.R, color.G, color.B));
            }
        }

        this.reflejo = reflejo;
        actualizando = false;
        this.Invoke(new EventHandler(refrescar));
    }
    catch
    {
        this.reflejo = null;
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here