为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
慕仙森 2022-06-12 14:29:02
我正在用 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 适合这个?
查看完整描述

1 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

您可以从 PictureBox 继承并在其上绘制一个半透明的白色矩形,而不是更改图像:


public class FlashingPictureBox : PictureBox

{

    private int flashIntensity;


    public int FlashIntensity

    {

        get

        {

            return flashIntensity;

        }

        set

        {

            if (flashIntensity == value)

            {

                return;

            }


            flashIntensity = value;

            Invalidate();

        }

    }


    protected override void OnPaint(PaintEventArgs pe)

    {

        base.OnPaint(pe);

        if (FlashIntensity == 0)

        {

            return;

        }


        using (SolidBrush brush = new SolidBrush(Color.FromArgb(FlashIntensity, 255, 255, 255)))

        {

            pe.Graphics.FillRectangle(brush, ClientRectangle);

        }

    }

然后将FlashIntensity属性设置为 0..255 以使它们亮起。


至于动画,我将创建一个单独的类,它采用“目标”图片框,并且可以通过自动画开始以来的毫秒数计算每个图片框所需的强度。


以下内容并不完全符合您的要求,但它可能会提供有关如何在单独的类中管理动画的想法:


public class WinAnimation

{

    private readonly FlashingPictureBox[] boxes;

    private readonly int started;

    const int singleFlashDuration = 700;

    const int nextBoxDelay = 100;

    const int duration = 3000;


    public WinAnimation(params FlashingPictureBox[] boxes)

    {

        this.boxes = boxes;

        started = Environment.TickCount;

    }


    /// <summary>

    /// Performs the animation at the indicated point in time.

    /// </summary>

    /// <param name="elapsed">The time elapsed since the animation started, in milliseconds</param>

    /// <returns>true if the animation is running, false if the animation is completed</returns>

    public bool Animate()

    {

        int elapsed = Environment.TickCount - started;

        if (elapsed >= duration)

        {

            foreach (var box in boxes)

            {

                box.FlashIntensity = 0;

            }


            return false;

        }


        for (int i = 0; i < boxes.Length; i++)

        {

            var box = boxes[i];

            int boxElapsed = elapsed - i * nextBoxDelay;

            if (boxElapsed < 0)

            {

                box.FlashIntensity = 0;

            }

            else

            {

                int intensity = (boxElapsed % singleFlashDuration);

                intensity = (intensity * 255) / singleFlashDuration;

                box.FlashIntensity = intensity;

            }

        }


        return true;

    }

}

假设您有一个计时器,您可以按如下方式从您的表单中调用它:


    private WinAnimation ani; // the animation object


    private void button1_Click(object sender, EventArgs e)

    {

        ani = new WinAnimation(flashingPictureBox1, flashingPictureBox2, flashingPictureBox3, flashingPictureBox4, flashingPictureBox5);

        timer1.Enabled = true;

    }


    private void timer1_Tick(object sender, EventArgs e)

    {

        if (!ani.Animate())

        {

            timer1.Enabled = false;

            ani = null;

        }

    }


查看完整回答
反对 回复 2022-06-12
  • 1 回答
  • 0 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号