C# 图像间的图像过渡效应
我读了这篇文章 并在我的应用程序中实现代码,但问题是图像变化太快,因为C# 图像间的图像过渡效应,c#,winforms,C#,Winforms,我读了这篇文章 并在我的应用程序中实现代码,但问题是图像变化太快,因为timer1.Interval=50当我将timer Interval增加到300时,我发现转换效果不太好 因此,请看我的代码,并给我建议,作为两个图像之间的结果转换,我需要在代码中更改的内容应该看起来良好且平滑,但我将能够为我的主计时器设置任何间隔值 using System; using System.IO; using System.Drawing; using System.Windows.Forms; namesp
timer1.Interval=50
当我将timer Interval增加到300时,我发现转换效果不太好
因此,请看我的代码,并给我建议,作为两个图像之间的结果转换,我需要在代码中更改的内容应该看起来良好且平滑,但我将能够为我的主计时器设置任何间隔值
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace BlendSlideShow
{
public partial class Form1 : Form
{
private float mBlend;
private int mDir = 1;
public int count = 0;
public Bitmap[] pictures;
public Form1()
{
InitializeComponent();
pictures = new Bitmap[9];
pictures[0] = new Bitmap(GetImgFolderPath() + "img1.jpg");
pictures[1] = new Bitmap(GetImgFolderPath() + "img2.jpg");
pictures[2] = new Bitmap(GetImgFolderPath() + "img3.jpg");
pictures[3] = new Bitmap(GetImgFolderPath() + "img4.jpg");
pictures[4] = new Bitmap(GetImgFolderPath() + "img5.jpg");
pictures[5] = new Bitmap(GetImgFolderPath() + "img6.jpg");
pictures[6] = new Bitmap(GetImgFolderPath() + "img7.jpg");
pictures[7] = new Bitmap(GetImgFolderPath() + "img8.jpg");
pictures[8] = new Bitmap(GetImgFolderPath() + "img9.jpg");
timer1.Interval = 50; //time of transition
timer1.Tick += BlendTick;
try
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[++count];
}
catch
{
}
timer1.Enabled = true;
}
private string GetImgFolderPath()
{
string _Path = Path.GetDirectoryName(Application.ExecutablePath) + @"\..\..\images\";
return _Path;
}
private void BlendTick(object sender, EventArgs e)
{
mBlend += mDir * 0.02F;
if (mBlend > 1)
{
mBlend = 0.0F;
if ((count + 1) < pictures.Length)
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[++count];
}
else
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[0];
count = 0;
}
}
blendPanel1.Blend = mBlend;
}
}
}
使用系统;
使用System.IO;
使用系统图;
使用System.Windows.Forms;
名称空间BlendSlideShow
{
公共部分类Form1:Form
{
私人浮标;
私有int mDir=1;
公共整数计数=0;
公共位图[]图片;
公共表格1()
{
初始化组件();
图片=新位图[9];
图片[0]=新位图(GetImgFolderPath()+“img1.jpg”);
图片[1]=新位图(GetImgFolderPath()+“img2.jpg”);
图片[2]=新位图(GetImgFolderPath()+“img3.jpg”);
图片[3]=新位图(GetImgFolderPath()+“img4.jpg”);
图片[4]=新位图(GetImgFolderPath()+“img5.jpg”);
图片[5]=新位图(GetImgFolderPath()+“img6.jpg”);
图片[6]=新位图(GetImgFolderPath()+“img7.jpg”);
图片[7]=新位图(GetImgFolderPath()+“img8.jpg”);
图片[8]=新位图(GetImgFolderPath()+“img9.jpg”);
timer1.Interval=50;//转换时间
timer1.Tick+=BlendTick;
尝试
{
blendPanel1.Image1=图片[计数];
blendPanel1.Image2=图片[++计数];
}
抓住
{
}
timer1.Enabled=true;
}
私有字符串GetImgFolderPath()
{
字符串\u Path=Path.GetDirectoryName(Application.ExecutablePath)+@“\..\..\images\”;
返回路径;
}
私有void BlendTick(对象发送方,事件参数e)
{
mBlend+=mDir*0.02F;
如果(mBlend>1)
{
mBlend=0.0F;
如果((计数+1)
我的完整代码
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace BlendSlideShow
{
public partial class Form1 : Form
{
private float mBlend;
private int mDir = 1;
public int count = 0;
public Bitmap[] pictures;
public Form1()
{
InitializeComponent();
pictures = new Bitmap[9];
pictures[0] = new Bitmap(GetImgFolderPath() + "img1.jpg");
pictures[1] = new Bitmap(GetImgFolderPath() + "img2.jpg");
pictures[2] = new Bitmap(GetImgFolderPath() + "img3.jpg");
pictures[3] = new Bitmap(GetImgFolderPath() + "img4.jpg");
pictures[4] = new Bitmap(GetImgFolderPath() + "img5.jpg");
pictures[5] = new Bitmap(GetImgFolderPath() + "img6.jpg");
pictures[6] = new Bitmap(GetImgFolderPath() + "img7.jpg");
pictures[7] = new Bitmap(GetImgFolderPath() + "img8.jpg");
pictures[8] = new Bitmap(GetImgFolderPath() + "img9.jpg");
timer1.Interval = 50; //time of transition
timer1.Tick += BlendTick;
try
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[++count];
}
catch
{
}
timer1.Enabled = true;
}
private string GetImgFolderPath()
{
string _Path = Path.GetDirectoryName(Application.ExecutablePath) + @"\..\..\images\";
return _Path;
}
int numberOfTicks;
int ticksBeforeBlendStarts = 100;
private void BlendTick(object sender, EventArgs e)
{
if (numberOfTicks >= ticksBeforeBlendStarts)
{
mBlend += mDir * 0.02F;
if (mBlend > 1)
{
mBlend = 0.0F;
if ((count + 1) < pictures.Length)
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[++count];
}
else
{
blendPanel1.Image1 = pictures[count];
blendPanel1.Image2 = pictures[0];
count = 0;
}
numberOfTicks = 0;
}
blendPanel1.Blend = mBlend;
}
numberOfTicks++;
}
}
}
使用系统;
使用System.IO;
使用系统图;
使用System.Windows.Forms;
名称空间BlendSlideShow
{
公共部分类Form1:Form
{
私人浮标;
私有int mDir=1;
公共整数计数=0;
公共位图[]图片;
公共表格1()
{
初始化组件();
图片=新位图[9];
图片[0]=新位图(GetImgFolderPath()+“img1.jpg”);
图片[1]=新位图(GetImgFolderPath()+“img2.jpg”);
图片[2]=新位图(GetImgFolderPath()+“img3.jpg”);
图片[3]=新位图(GetImgFolderPath()+“img4.jpg”);
图片[4]=新位图(GetImgFolderPath()+“img5.jpg”);
图片[5]=新位图(GetImgFolderPath()+“img6.jpg”);
图片[6]=新位图(GetImgFolderPath()+“img7.jpg”);
图片[7]=新位图(GetImgFolderPath()+“img8.jpg”);
图片[8]=新位图(GetImgFolderPath()+“img9.jpg”);
timer1.Interval=50;//转换时间
timer1.Tick+=BlendTick;
尝试
{
blendPanel1.Image1=图片[计数];
blendPanel1.Image2=图片[++计数];
}
抓住
{
}
timer1.Enabled=true;
}
私有字符串GetImgFolderPath()
{
字符串\u Path=Path.GetDirectoryName(Application.ExecutablePath)+@“\..\..\images\”;
返回路径;
}
int numberOfTicks;
int ticksBeforeBlendStarts=100;
私有void BlendTick(对象发送方,事件参数e)
{
如果(numberOfTicks>=在借贷开始前勾选)
{
mBlend+=mDir*0.02F;
如果(mBlend>1)
{
mBlend=0.0F;
如果((计数+1)
a)在50和300之间有很多值,对吗?仅以两组速度播放音乐也会失败b) 也许学习会有帮助。试捕的最佳用法!顺便说一句:我使用这个小小的库得到了很棒的结果。该死,这是我的代码。你需要另一个定时器来延迟两次转换之间的时间,这样用户可以看一段时间的图像。我从来没有声称代码是由编写的,而是在顶部我提到了从哪里获得代码的url。