TImageList - True color + alpha channel vs. 8-bit (256 colors)

空扰寡人 提交于 2019-12-24 14:54:11

问题


I use c++ Builder 2009 but I tagged this for Delphi as well since I expect the exact same issue to exist there as well.

I use TImageList (16x16) and associate it to TListView (SmallImages) and TTreeView.

I was adding new icons via the IDE (design time) and imported some 16x16 True color + alpha channel icons. In the IDE they looked fine:

During run time, they do not look fine at all:

Notice the edges especially. The top icon is icon 5 and the bottom icon is icon 7. See how they are supposed to look in above picture.

When I convert the icons to 8 bit (256 colors) icons and import them via the IDE, they look fine during run time ! So that is certainly a solution for me. But the icons obviously lose information and though probably hardly noticeable in 16x16 icons, it sort of bugs me that I cannot find why this happens ?

The ImageList is created at design time and has its default properties.

I also tried: DrawingStyle = dsTransparent and ColorDepth = cd32Bit after which I had to import the icons again via the IDE. The result is the same. I wonder if I need to set a particular BlendColor ?

Do I need to do something special for it to support true color icons ? Or is the issue with TTreeView and TListView ? Is this a VCL limitation or Windows or .. Thoughts, suggestions ?

- Additional information - after having read David's comment.

I added a new TImageList to my project and added the 32bit icons with alpha channel. Next I 'hacked' my code to always use that ImageList and it worked beautifully.

What I do in the code is, because I have a set of icons that I use for all OS (very application related) and because I also use icons that are OS specific, such as folder icons, CD icons etc. I have an ImageList that contains all icons (OS and app specific) and on program start and OS check, I copy the OS icons that I need from one list to the list that I use.

Like so:

TIcon *Icon = new TIcon() ;
for (int x = 0 ; x < OS_Specific_count ; x++)
  {
  OS_xx_ImageList->GetIcon(x, Icon) ;
  Use_ImageList->ReplaceIcon(x, Icon) ; 
  }
delete Icon ;

I fear the issue is in this part of the code !

- Additional information - after having done more testing

If I rewrite the code to something like:

TBitmap *Bitmap= new TBitmap () ;
for (int x = 0 ; x < OS_Specific_count ; x++)
  {
  OS_xx_ImageList->GetBitmap(x, Bitmap) ;
  Use_ImageList->Replace(x, Bitmap, NULL) ; 
  }
delete Bitmap;

I have similar problems, yet not exactly the same. The transparency seems to get lost !

I have also noticed that:

Use_ImageList->AddImage(OS_xx_ImageList, x) ;

starting from an empty Use_ImageList seems to preserve all alpha channel data properly ! Maybe I should rewrite the code to always copy the lot this way ...

来源:https://stackoverflow.com/questions/35121272/timagelist-true-color-alpha-channel-vs-8-bit-256-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!