C# Listview图像质量变低
我在玩我的C# Listview图像质量变低,c#,winforms,listview,imagelist,C#,Winforms,Listview,Imagelist,我在玩我的列表框,但我意识到,因为这样,图像的质量突然下降。listbox使用imagelist控件查看其图标。这是我的设计器代码中的我的列表框和我的图像列表属性 列表视图: this.listviewFiles.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.listview
列表框
,但我意识到,因为这样,图像的质量突然下降。listbox
使用imagelist
控件查看其图标。这是我的设计器代码中的我的列表框
和我的图像列表
属性
列表视图:
this.listviewFiles.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listviewFiles.LargeImageList = this.imageListFiles;
this.listviewFiles.Location = new System.Drawing.Point(3, 14);
this.listviewFiles.Name = "listviewFiles";
this.listviewFiles.Size = new System.Drawing.Size(761, 392);
this.listviewFiles.TabIndex = 4;
this.listviewFiles.UseCompatibleStateImageBehavior = false;
this.listviewFiles.SelectedIndexChanged += new System.EventHandler(this.listviewFiles_SelectedIndexChnaged);
this.listviewFiles.Click += new System.EventHandler(this.listviewFiles_Click);
图像列表
this.imageListFiles.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListFiles.ImageStream")));
this.imageListFiles.TransparentColor = System.Drawing.Color.Transparent;
this.imageListFiles.Images.SetKeyName(0, "csv.ico");
this.imageListFiles.Images.SetKeyName(1, "sql.ico");
当前图像质量
图片的真实质量
加载的图像为PNG或ICO格式时,图像列表图像的质量降低是一个常见问题。我在WinFormC应用程序中也经历过这种情况 图像列表图像作为Base64编码图像序列化到表单的.resx文件中,我认为序列化图像时存在错误,因为当它们被序列化多次时,您肯定会看到质量下降(可能是alpha/transparency通道出现问题)。然后,当您从图像列表中删除图像并再次添加它们时,它们看起来很好,直到图像列表被序列化几次并且质量下降再次可见 我通过简单地避免在应用程序中使用图像列表解决了这个问题。使用图像数组或图像字典也可以很好地解决质量下降问题。如果仍然要使用图像列表,可能的解决方案是在运行时创建并填充图像列表,而不使用设计器。您能试试这个吗
ImageList largeImageList = new ImageList();
largeImageList.ColorDepth = ColorDepth.Depth32Bit;
largeImageList.ImageSize = new Size(64, 64); //actual size of image
largeImageList.Images.Add(Properties.Resources.psd64);
ListView listView = new ListView();
listView.LargeImageList=largeImageList;
我认为这将永远解决您的问题:)设置了什么imageList控制imageSize和什么是原始图片大小?@Reniuz两者都是
64x64
。我的列表框的LargeImageList
ColorDepth设置为Depth32Bit
。你的文档不完善,“真实质量”的图像是JPEG格式,我不能告诉你关于原始格式的任何信息。“质量不好”的图像没有合适的大小,我不知道这是造成质量损失的原因,还是只是制作截图的副作用。你必须创建一个复制项目,以便有人可以下载它,并知道它真正的样子。@HansPassant真正的图像是一个.ico
文件,如我所说,它是64x64
,深度为32。如果它被重新调整大小,我想知道它会发生在哪里。@HansPassant但是我刚刚在我的imagelist
中注意到一件奇怪的事情,当我第一次更改图像时,它们会得到PhysicalDimension
属性32x32
,当我添加它们后再次查看时,这个属性会变回64x64
。这可能是原因吗?此属性是只读的。