通过图像列表显示时图像质量下降

dis*_*kid 5 c# image imagelist picturebox winforms

我想ImageList使用计时器循环显示图像。它工作正常,除了PictureBoxPictureBox它应该显示图像列表中的图片时,在a上生动显示的相同图像会失去其质量。

直接显示时的图像PictureBox

在此处输入图片说明

显示在PictureBox但通过ImageList( pictureBox1.Image = imglist.Images[0];) 时的图像:

在此处输入图片说明

我的图片是一个128x128png,这里是我PictureBox和我的设计器代码ImageList

// 
// pictureBox1
// 
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(378, 78);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(128, 128);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;

// 
// imglist
// 
this.imglist.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imglist.ImageStream")));
this.imglist.TransparentColor = System.Drawing.Color.Transparent;
this.imglist.Images.SetKeyName(0, "1423093311_supportfemale-48.png");
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

小智 0

使用 PictureBox 的 ImageList 显示图像有时会降低图像质量。

尝试这个替代方案:

  1. 右键单击“项目”>选择“属性”>从左侧选项卡中选择“资源”>从水平菜单中选择图像>单击“添加资源”(从您的计算机添加所需的图像)>“保存”...这会将图像添加到具有图像名称.扩展名的资源中

  2. 在fromNameLoad(首先执行的任何加载方法)中,写入:
    Image imagename1 = Properties.Resources。图像名称

  3. 与 PictureBox 一起使用: PictureboxVar.BackgroundImage = imagename1 ;