如何替换 winforms 上的现有图像ImageList
?
我试过这个:
this.CoolPics.Images [ 2 ] = // new image
this.ListViewControl.SmallImageList = this.CoolPics;
但是,当我使用该this.CoolPics.Images.Add
方法时,新图像不会像其他图像那样重新缩放。
我究竟做错了什么?
我知道这很旧,但这是我解决问题的方法。看起来图像列表不会在分配时调整图像大小(即使它在使用 Add() 函数时会调整)。所以基本上,您需要在分配之前手动调整图像大小。
Image img; //used to load new image from disk
Bitmap bmp = new Bitmap(160, 120); //canvas where the new image will be drawn/resized
Graphics graph = Graphics.FromImage(bmp); //used to draw/resize the new image
img = new Bitmap(fileDialog.FileNames[0]); //load new image from disk
graph.DrawImage(img, new Rectangle(0, 0, 160, 120)); //resize new image to proper size
imgList.Images[index] = bmp; //assign the new resized image to the list (overwrites the old image)
I have run into this before and if I remember right the assignment operator had this behavior but the Imagelist.Images.Add(myImage) did the right thing.
Try changing your code to do the .Add(myImage) and see if that doesn't look better.
在你的代码尝试之后
listView1.Refresh();