Moving picture

  • Thread starter Thread starter Davis
  • Start date Start date
D

Davis

Hi, I have an app which displays a sequence of png images, these
are copied into PictureBox as shown below. This sequence is done
in its own thread, its just that the single line
'picImage.Image = New Bitmap(arrimg(cnt) & ".png")'
is killing performance, also generating InvalidCastException. How can
i improve this? Basically it cycles through an array of png files under
timer control.


If Not (Me.picImage.Image Is Nothing) Then
Me.picImage.Image.Dispose()
End If
picImage.Image = New Bitmap(arrimg(cnt) & ".png")
 
Forgot to mention i'm using VS2005 that line of code kills performance
on PocketPC 2003 emulator and device
 
The simplest solution that I can suggest you is to create custom
control, place into it a Timer control, override OnPaint method in this
manner:

protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.DrawImage(_imageCollection[_currentImageIndex], 0, 0);
}

and add timer tick handler:

Image _imageCollection[N];
int _currentImageIndex = 0;

.... here goes image collection filling ...

private void timer1_Tick(object sender, EventArgs e)
{
_currentImageIndex = (_currentImageIndex + 1) % N;
Invalidate();
}


It's just a sketch but I hope you've got the idea.
 
Thanks, Sergey so what yo uare saying is put the
images into a collection ie don't keep calling the
Bitmap constructor


Sergey Bogdanov said:
The simplest solution that I can suggest you is to create custom control,
place into it a Timer control, override OnPaint method in this manner:

protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.DrawImage(_imageCollection[_currentImageIndex], 0, 0);
}

and add timer tick handler:

Image _imageCollection[N];
int _currentImageIndex = 0;

... here goes image collection filling ...

private void timer1_Tick(object sender, EventArgs e)
{
_currentImageIndex = (_currentImageIndex + 1) % N;
Invalidate();
}


It's just a sketch but I hope you've got the idea.


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Forgot to mention i'm using VS2005 that line of code kills performance
on PocketPC 2003 emulator and device
 
Back
Top