سؤال

ما هي أفضل طريقة (أقل ثقيلة الموارد) لتتلاشى صورة داخل وخارج كل 20 ثانية مع مدة ثانية واحدة، مقابل خلفية سوداء (شاشة التوقف)، في C #؟

(صورة حوالي 350x130px).

أحتاج إلى هذا لشاشة توقف بسيطة سيتم تشغيلها على بعض أجهزة كمبيوتر منخفضة المستوى (XP).

الآن أنا أستخدم هذه الطريقة مقابل صندوق الصور، لكنها بطيئة جدا:

    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;
    }
هل كانت مفيدة؟

المحلول

ربما يمكنك استخدام مصفوفة اللون مثل في هذا المثال على MSDN

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

نصائح أخرى

بدلا من استخدام طريقة القلم وطريقة التصوير ()، يمكنك استخدامها bitmap.lockbits. للوصول إلى ذاكرة صورتك مباشرة. هنا تفسير جيد كيف يعمل.

ضع مؤقتا على النموذج الخاص بك، وفي المنشئ، أو form_load، الكتابة

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

أضف طريقة خاصة

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

هنا بلدي تأخذ على هذا

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

يوصى أيضا بإنشاء مؤشر ترابط آخر لأن هذا سيؤدي إلى تجميد مفتاحك الرئيسي.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top