dizzy.stackoverflow dizzy.stackoverflow - 17 days ago 9
C# Question

Low quality image in TabPage header using TabControl ImageList

I'm having a problem with the image quality of the image that is displayed on the TabPage header. My source image is a 16x16 png with transparency. When I load it into the TabPage header, the quality is horrible. So far, the best I've been able to come up with is to use an 8 bit png instead of a 32 bit png. This helps significantly, but the quality is still not as good as I would like, and still not as good as a 32 bit png. Does anyone have a good method of preserving the png quality?

(32 bit original on left. 32 bit tab header lower quality on right.)

enter image description here

(8 bit original on left. 8 bit tab header lower quality on right.)

enter image description here

(32 bit original on left. 8 bit tab header lower quality on right.)

enter image description here

I'm trying/hoping to get it as close as possible to looking like the original 32 bit png.

I'm using the below code:

using System.Drawing;
using System.Windows.Forms;

public class Form1
{
public void Form1()
{
InitializeComponent();

// initialize the imagelist
ImageList imageList1 = new ImageList();
imageList1.Images.Add("key1", Properties.Resources.Image1png);
imageList1.Images.Add("key2", Properties.Resources.Image2png);

//initialize the tab control
TabControl tabControl1 = new TabControl();
tabControl1.Dock = DockStyle.Fill;
tabControl1.ImageList = imageList1;
tabControl1.TabPages.Add("tabKey1", "TabText1", "key1");
tabControl1.TabPages.Add("tabKey2", "TabText2", "key2");
this.Controls.Add(tabControl1);
}
}

Answer

Not sure if this answers your question, but have to post it as answer to include the snapshot.

You might try below:

  1. Select the image list;
  2. Config the ColorDepth property, and set it from "Depth8bit" to "Depth32bit"

enter image description here

Or simply change it in code:

imageList1.ColorDepth = ColorDepth.Depth32Bit;
Comments