私の提案は1 List<Bitmap>
にすべての画像をロードしPictureBox
内の画像を変更するためにTimer
を使用することです:
List<Bitmap> _images = new List<Bitmap>();
int _currentImageIndex = 0;
int CurrentImageIndex
{
get { return _currentImageIndex; }
set {
_currentImageIndex = value;
if (InvokeRequired)
{
Invoke(new MethodInvoker(() => { _pictureBox.Image = _images[_currentImageIndex]; });
}
else
{
_pictureBox.Image = _images[_currentImageIndex];
}
}
}
Bitmap LoadImage(Stream stream)
{
return new Bitmap(stream, false);
}
public void LoadImages(DirectoryInfo dInfo)
{
foreach(FileInfo fInfo in dInfo.GetFiles())
{
if(InvokeRequired)
{
Invoke(new MethodInvoker(() => { _images.Add(LoadImage (fInfo.Open(FileMode.Open))); });
}
else
{
_images.Add(LoadImage (fInfo.Open()));
}
}
}
void WhenTimerTicks(object sender, EventArgs e)
{
if(CurrentImageIndex < _images.Count)
CurrentImageIndex++;
}
今あなたがしなければならないすべてのファイルを読み取ることで、その後、あなたのタイマー設定:
LoadImages(new DirectoryInfo("c:\\Users\\" + Environment.UserName + "\\Desktop\\fireplace"));
Timer t = new Timer();
t.Interval = 1000/25; // 25 FPS
t.Tick += WhenTimerTicks;
t.Start();
[Image.FromFile](https://msdn.microsoft.com/en-us/library/system.drawing.image.fromfile(v = vs.110).aspx)を使用してください。 –
また、 'System.Windows.Forms.Timer'の後にイメージが切り替わります。 – BladeMight
John Wu、サンプルコードを表示できますか?私のようなnoob私はそれを使用する方法を知っている> _ < – diPokiI