当通过图像列表显示时,图像会失去质量。

5
我想使用ImageList通过一个定时器来循环显示图片,它能正常工作,但是同样的图片在PictureBox中以较高的清晰度显示,当使用ImageList来显示相同的PictureBox时就会失去质量。
在PictureBox直接显示图片时的效果: enter image description here 在PictureBox中使用ImageList来显示图片时的效果(pictureBox1.Image = imglist.Images[0];): enter image description here 我的图片是一张128x128的png图片,以下是我的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");

enter image description here


@Hughnited 是的,但我得到了相同的结果。 - disasterkid
1
从图片上看,似乎并没有失去质量,而是imageList添加了边框... - Dominik B
@DominikB 是的。但是它为什么会出现呢? - disasterkid
1
这里有一个类似问题的链接:https://dev59.com/mGPVa4cB1Zd3GeqP30L6 - Hugh
您正在看到半透明像素的影响。如果可以的话,请尽量避免使用它们! - TaW
显示剩余2条评论
1个回答

0

使用 ImageList 顯示圖像時,有時會降低圖像質量。

嘗試這個替代方法:

  1. 右鍵單擊項目 > 選擇屬性 > 從左側選擇資源 > 從水平菜單中選擇圖像 > 點擊添加資源(從計算機中添加所需圖像)> 儲存... 這將使用 imagename.extension 將圖像添加到資源中。

  2. 在 fromNameLoad(執行第一個載入方法)中撰寫:
    Image imagename1 = Properties.Resources.imagename;

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接