开发者

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 = i开发者_开发百科mageList1.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?


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


MSDN-> "ImageList is typically used by other controls, such as the ListView, TreeView, or ToolBar". Although you may be able to use ImageList your way you might be seeing some of unintended side effects of using it that way. Try using a List of images instead of an ImageList.

List<Image> images = new List<Image>();

// assign images.  images.Add(...

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


I get the same problem where every once in a while, the form resource file decides to provide a lower resolution image format for my image list.

I have to delete the images from the image list and re-add them to get the full resolution back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜