Pregunta

¿Cuál es la mejor manera (menos de recursos pesada) a desvanecerse una imagen dentro y fuera cada 20 segundos, con una duración de 1 segundo contra un fondo negro (protector de pantalla), en C #?

(una imagen de 350x130px).

Necesito esto para un simple protector de pantalla que va a ejecutar en algunos equipos de bajo nivel (XP).

En este momento estoy usando este método frente a un cuadro de imagen, pero es demasiado lento:

    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;
    }
¿Fue útil?

Solución

Probablemente se podría utilizar una matriz de color como en este ejemplo en MSDN

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

Otros consejos

En lugar de utilizar un método DrawLine () de la pluma y, puede utilizar Bitmap.LockBits para acceder a la memoria de su imagen directamente. He aquí una buena explicación de cómo funciona.

Ponga un temporizador en su forma y en el constructor, o el Form_Load, escribir

    timr.Interval = //whatever interval you want it to fire at;
    timr.Tick += FadeInAndOut;
    timr.Start();

Añadir un método privado

private void FadeInAndOut(object sender, EventArgs e)
{
    Opacity -= .01; 
    timr.Enabled = true;
    if (Opacity < .05) Opacity = 1.00;
}

Esta es mi opinión sobre este

    private void animateImageOpacity(PictureBox control)
    {
        for(float i = 0F; i< 1F; i+=.10F)
        {
            control.Image = ChangeOpacity(itemIcon[selected], i);
            Thread.Sleep(40);
        }
    }

    public static Bitmap ChangeOpacity(Image img, float opacityvalue)
    {
        Bitmap bmp = new Bitmap(img.Width, img.Height); // Determining Width and Height of Source Image
        Graphics graphics = Graphics.FromImage(bmp);
        ColorMatrix colormatrix = new ColorMatrix {Matrix33 = opacityvalue};
        ImageAttributes imgAttribute = new ImageAttributes();
        imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute);
        graphics.Dispose();   // Releasing all resource used by graphics 
        return bmp;
    }

También es recomendable para crear otro hilo, ya que esto congelar su principal.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top