문제

C#에서 검은 색 배경 (스크린 세이버)에 대해 1 초의 지속 시간으로 20 초마다 이미지를 유입하거나 아웃하는 가장 좋은 (최소 리소스 무거운) 방법은 무엇입니까?

(350x130px에 대한 이미지).

낮은 수준의 컴퓨터 (XP)에서 실행되는 간단한 스크린 세이버의 경우 이것을 필요로합니다.

지금은이 메소드를 PictureBox에 사용하고 있지만 너무 느립니다.

    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

다른 팁

펜과 Drawline () 메소드를 사용하는 대신 사용할 수 있습니다. 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