Recent

Author Topic: BitBtn - display error  (Read 3528 times)

Ally

  • Jr. Member
  • **
  • Posts: 53
BitBtn - display error
« on: March 01, 2022, 12:13:31 pm »
An icon with transparent image areas is not displayed correctly on a BitBtn.
Partially transparent pixels are not rendered with their actual color, but as a gray tone.
This results in very unattractive display errors, especially where transparent pixels are used to provide a smoother display.
So far I have only noticed this problem with BitBtn. SpeedButton, DirectoryEdit, ToolButton or MenuItem's render the icons correctly.
Attached is an example to illustrate the problem. (Win10, Lazarus 2.2.0 FPC 3.2.2 x86_64-win64-win32/win64)

Some time ago I wrote a bugreport about this and in the meantime I saw that there are some more reports describing this bug.
Unfortunately there was no feedback in the bugtracker.

In the German Lazarus forum I also addressed this (https://www.lazarusforum.de/viewtopic.php?p=124148#p124148).

Thereby it turned out:
That the problem is only present under Windows.
TBitBtn is a TWinControl descendant.
TSpeedButton is a TGraphicControl descendant and does not have the problem.

Now I'm not exactly an expert in this field, but I tried to get to the bottom of it anyway. Unfortunately without success.

So my question to you is: who knows something about this and can localize the place where the BitBtn icon is drawn, different from the other components.
Maybe a few small hints are enough to make it easier for the experts in the developer team to get started.

Here is an enlarged view where you can see the difference well.


wp

  • Hero Member
  • *****
  • Posts: 11910
Re: BitBtn - display error
« Reply #1 on: March 01, 2022, 12:24:36 pm »
An icon with transparent image areas [...]
Just to make sure: you loaded the image list in your demo with alpha-channel png images rather than with transparent ico files as your description might suggest?

Since only TBitBtn is affected and since this is drawn by the widgetset I'd guess that this probably is a Windows issue, or calling out-dated painting painting routines from the era when alpha-channel transparency was still unknown to Windows. BTW, could you check out your demo with Delphi?

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: BitBtn - display error
« Reply #2 on: March 01, 2022, 12:47:17 pm »
Tested the OP's BitBtnDisplayError.zip on Lazarus 2.2.0 64-bit GTK2 Ubuntu Mate 21.10. All the icons seem okay, see the attached screenshot (400% zoom):
« Last Edit: March 01, 2022, 12:51:02 pm by Handoko »

Ally

  • Jr. Member
  • **
  • Posts: 53
Re: BitBtn - display error
« Reply #3 on: March 01, 2022, 01:13:16 pm »
@wp

Quote
Just to make sure: you loaded the image list in your demo with alpha-channel png images rather than with transparent ico files as your description might suggest?

Yes, of course the "Icons" are as usual transparent PNG's which are inserted over an ImageList.

Quote
BTW, could you check out your demo with Delphi?

My last Delphi is version 7 and there, without additional extensions, only BMP's without transparency are supported.
But the idea is good. Maybe someone, who has a current Delphi, is so kind and tests this briefly?


@Handoko

Thanks for testing.
This confirms what I said above: The problem could only be observed under Windows so far.

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: BitBtn - display error
« Reply #4 on: March 01, 2022, 01:20:57 pm »
My last Delphi is version 7 and there, without additional extensions, only BMP's without transparency are supported.
But the idea is good. Maybe someone, who has a current Delphi, is so kind and tests this briefly?
Oh what a mess! I have the XE10.3.3 community edition, and even today they only allow me to load bmp into TBitBtn.Glyph! Then I remembered that they equipped TButton with a TImageList now, and TImageList does allow me to load png, but the images now have a black background.

Ally

  • Jr. Member
  • **
  • Posts: 53
Re: BitBtn - display error
« Reply #5 on: March 01, 2022, 02:57:41 pm »
Quote
and even today they only allow me to load bmp into TBitBtn.Glyph!

Actually, this does not surprise me. TBitBtn.Glyph exists, in my opinion, only for compatibility reasons and should not be used currently.

Quote
TImageList does allow me to load png, but the images now have a black background.

That surprises me now however very much. That would mean that TImageList is not useable in Delphi?

Enclosed are some "icons" for testing.

Ally

  • Jr. Member
  • **
  • Posts: 53
Re: BitBtn - display error
« Reply #6 on: March 01, 2022, 04:08:53 pm »
I noticed something else.
If you look at the font in programs, greatly enlarged, you can see that the individual letters are "smoothed" with colored and transparent pixels.
This is not only done by Windows, but also by Linux, as you can see in Handoko's screenshot.
And also here the BitBtn under Windows has a problem. The caption is only "smoothed" with gray pixels, which also leads to a slight degradation of the font quality.

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: BitBtn - display error
« Reply #7 on: March 01, 2022, 04:29:43 pm »
TBitBtn.Glyph exists, in my opinion, only for compatibility reasons and should not be used currently.
Not for Delphi where TBitBtn does not use an imagelist.

That would mean that TImageList is not useable in Delphi?
I remember that I had used TPngImageList in my Delphi7 days for this reason. But I am surprised that this did not change during the past 25 years.

However, things become a bit better when I add the images at runtime. When I load the png file into a TPngImage, assign it to a TBitmap and load that into a TImageList, the icon is displayed on a TButton correctly - similar to our TSpeedButton. On the other hand, when I assign the png to the Glyph of a TBitBtn I get an extremely low-quality image.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   png: TPngImage;
  4.   bmp: TBitmap;
  5. begin
  6.   png := TPngObject.Create;
  7.   try
  8.     png.LoadfromFile('D:\Prog_Lazarus\thirdparty_components\button_icons\Icon3-16.png');
  9.     bmp := TBitmap.Create;
  10.     try
  11.       bmp.Assign(png);
  12.       ImageList1.Add(bmp, nil);
  13.     finally
  14.       bmp.Free;
  15.     end;
  16.     BitBtn1.Glyph.Assign(png);
  17.   finally
  18.     png.Free;
  19.   end;
  20. end;

No, Delphi really is not a bench-mark here...

Ally

  • Jr. Member
  • **
  • Posts: 53
Re: BitBtn - display error
« Reply #8 on: March 01, 2022, 05:43:40 pm »
Quote
Not for Delphi where TBitBtn does not use an imagelist.

So Lazarus has the nose clearly in front. And the whole thing also with ImageList.Scaled, HighDPI capable.

Quote
I remember that I had used TPngImageList in my Delphi7 days for this reason. But I am surprised that this did not change during the past 25 years.

Yes, exactly, I still maintain two old Delphi programs and there I also use TPngImageList.

Quote
On the other hand, when I assign the png to the Glyph of a TBitBtn I get an extremely low-quality image.

But at least in both cases the caption is displayed correctly.

 

TinyPortal © 2005-2018