猿问

如何用一排图片框制作flash动画?

我正在用 C# 和 WinForm 创建著名的“Lingo”游戏,并且当这个词被正确猜到时,我就参与其中。我的“字母游戏”包含 25 个标签和 25 个图片框(用于 5 个字母游戏),我想像在真实电视游戏中一样为当前行设置动画示例1


我尝试通过 MS PowerPoint 制作视频(成功)并在背景中播放声音。但是视频显示在字母的顶部,因此不再可见。但为此,我必须为另一个游戏的新长度制作一个新视频。


在一些谷歌搜索之后,我发现图片编辑是可能的,所以我正在使用一个找到的程序的一部分,用于图片框的亮度编辑器。


        for (int x = 0; x != 5; x++)

        {

            float brightness = 1.0f; // no change in brightness

            float contrast = 1.0f; // twice the contrast

            float gamma = 1.0f; // no change in gamma


            float adjustedBrightness = brightness - 1.0f;

            // create matrix that will brighten and contrast the image

            float[][] ptsArray ={

            new float[] {contrast, 0, 0, 0, 0}, // scale red

            new float[] {0, contrast, 0, 0, 0}, // scale green

            new float[] {0, 0, contrast, 0, 0}, // scale blue

            new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha

            new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};


            ImageAttributes imageAttributes = new ImageAttributes();

            imageAttributes.ClearColorMatrix();

            imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);

            Graphics g = Graphics.FromImage(v[0, 1].BackgroundImage);

            g.DrawImage(v[0, 1].BackgroundImage, new Rectangle(0, 0, v[0, 1].BackgroundImage.Width, v[0, 1].BackgroundImage.Height)

                , 0, 0, v[0, 1].BackgroundImage.Width, v[0, 1].BackgroundImage.Height,

                GraphicsUnit.Pixel, imageAttributes);

        }

    }

但是亮度应该应用在所有 5 个当前行图片框上,但之后很少和之后将更多的亮度增加到最大值,然后降低亮度(用于闪光效果)。有没有办法以流畅的方式做到这一点/我应该使用视频选项还是上面的选项?或者也许 WinForm nog 适合这个?



慕仙森
浏览 145回答 1
1回答

繁星点点滴滴

您可以从 PictureBox 继承并在其上绘制一个半透明的白色矩形,而不是更改图像:public class FlashingPictureBox : PictureBox{&nbsp; &nbsp; private int flashIntensity;&nbsp; &nbsp; public int FlashIntensity&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; get&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return flashIntensity;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; set&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (flashIntensity == value)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flashIntensity = value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invalidate();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; protected override void OnPaint(PaintEventArgs pe)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; base.OnPaint(pe);&nbsp; &nbsp; &nbsp; &nbsp; if (FlashIntensity == 0)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; using (SolidBrush brush = new SolidBrush(Color.FromArgb(FlashIntensity, 255, 255, 255)))&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pe.Graphics.FillRectangle(brush, ClientRectangle);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}&nbsp;然后将FlashIntensity属性设置为 0..255 以使它们亮起。至于动画,我将创建一个单独的类,它采用“目标”图片框,并且可以通过自动画开始以来的毫秒数计算每个图片框所需的强度。以下内容并不完全符合您的要求,但它可能会提供有关如何在单独的类中管理动画的想法:public class WinAnimation{&nbsp; &nbsp; private readonly FlashingPictureBox[] boxes;&nbsp; &nbsp; private readonly int started;&nbsp; &nbsp; const int singleFlashDuration = 700;&nbsp; &nbsp; const int nextBoxDelay = 100;&nbsp; &nbsp; const int duration = 3000;&nbsp; &nbsp; public WinAnimation(params FlashingPictureBox[] boxes)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; this.boxes = boxes;&nbsp; &nbsp; &nbsp; &nbsp; started = Environment.TickCount;&nbsp; &nbsp; }&nbsp; &nbsp; /// <summary>&nbsp; &nbsp; /// Performs the animation at the indicated point in time.&nbsp; &nbsp; /// </summary>&nbsp; &nbsp; /// <param name="elapsed">The time elapsed since the animation started, in milliseconds</param>&nbsp; &nbsp; /// <returns>true if the animation is running, false if the animation is completed</returns>&nbsp; &nbsp; public bool Animate()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; int elapsed = Environment.TickCount - started;&nbsp; &nbsp; &nbsp; &nbsp; if (elapsed >= duration)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var box in boxes)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.FlashIntensity = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < boxes.Length; i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var box = boxes[i];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int boxElapsed = elapsed - i * nextBoxDelay;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (boxElapsed < 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.FlashIntensity = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int intensity = (boxElapsed % singleFlashDuration);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intensity = (intensity * 255) / singleFlashDuration;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.FlashIntensity = intensity;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; }}假设您有一个计时器,您可以按如下方式从您的表单中调用它:&nbsp; &nbsp; private WinAnimation ani; // the animation object&nbsp; &nbsp; private void button1_Click(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; ani = new WinAnimation(flashingPictureBox1, flashingPictureBox2, flashingPictureBox3, flashingPictureBox4, flashingPictureBox5);&nbsp; &nbsp; &nbsp; &nbsp; timer1.Enabled = true;&nbsp; &nbsp; }&nbsp; &nbsp; private void timer1_Tick(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (!ani.Animate())&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer1.Enabled = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ani = null;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
随时随地看视频慕课网APP
我要回答