在 C# 中使用 imageList 时图像分辨率较差
我使用的 imageList 存储了 5 个图像,其中 3 个是 .jpg,2 个是 .bmp。
我使用这些图像来使用计时器更改图片框图像 -
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[imgIndex++];
}
其中 private int imgIndex = 0;
在 Form
类中设置。
我有两个问题,首先,在图片框中显示的图像分辨率非常像素化且质量很差,我尝试通过更改 imageList< 中的
ColorDepth
来解决此问题/code> 属性,我也尝试使用不同的图像格式,即 .gif
、.png
等并更改图像大小,但这不起作用。我怎样才能获得更好的分辨率?
第二个问题是,当计时器到达最后一个图像时,应用程序崩溃并出现错误“InvalidArgument = Value of '5' is not valid for 'index.html”。参数名称:索引' imageList 中有 5 个图像,调试时出现 private int imgIndex = 0;
错误,我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 0 索引的 5 个图像,最大索引大小应为 4 而不是 5。这就是它在值 = 5 时给出错误的原因。对于分辨率,您需要将 SizeMode 属性设置为 Normal
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 通常由其他控件使用,例如 ListView、TreeView 或 ToolBar”。尽管您可以按照自己的方式使用 ImageList,但您可能会看到以这种方式使用它会产生一些意想不到的副作用。尝试使用图像列表而不是 ImageList。
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.
我遇到同样的问题,每隔一段时间,表单资源文件决定为我的图像列表提供较低分辨率的图像格式。
我必须从图像列表中删除图像并重新添加它们 获取完整分辨率。
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.