Search code examples
c#winformsresolutionpictureboximagelist

Poor image resolution when using imageList in C#


I am using an imageList which has 5 images stored, 3 of which are .jpg and 2 .bmp.

I am using these images to change a picturebox image using a timer -

private void timer1_Tick(object sender, EventArgs e)
    {
        pictureBox1.Image = imageList1.Images[imgIndex++];
    }

where private int imgIndex = 0; is set in the Form class.

I have 2 problems, firstly the resolution of the images when displayed in the picture box is very pixelated and of poor quality, and I have tried to resolve this by changing the ColorDepth in the imageList properties and I have also tried using different image formats i.e. .gif, .png etc and altering the image size but this does not work. How can I get a better resolution?

The second problem is when the timer gets to the last image, the application crashes with the error 'InvalidArgument=Value of '5' is not valid for 'index. Parameter name: index' There are 5 images in the imageList and when debugging the error arises from private int imgIndex = 0; how can I resolve this?


Solution

  • for 5 images with 0 index, max index size should be 4 not 5. That's the reason it gives error on value = 5. For resolution, you need to set SizeMode property to Normal