TrayIcon doesn't transfer transparent colour from bitmap to trayicon properly
Original Reporter info from Mantis: dieselnutjob
-
Reporter name: Philip
Original Reporter info from Mantis: dieselnutjob
- Reporter name: Philip
Description:
If I create a windows .ico file with some transparent pixels
and do
TrayIcon1.Icon.LoadFromFile('icon.ico');
TrayIcon1.Show;
then the icon is displayed correctly.
However, if I load a TBitmap and assign a colour as transparent
then do
TrayIcon1.Icon.Assign(bmp);
TrayIcon1.Show;
the icon doesn't display properly.
It appears to corrupt the entire rows in the bitmap that contain pixels with the transparent colour.
I can draw the same bitmap to Image1.Canvas and it is displayed properly with transparency as expected.
Additional information:
example code
icon.bmp is a 16x16 bitmap file with 24 bit RGB colour and a grey box in the middle. see zip file
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
TrayIcon1: TTrayIcon;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
buffer: THandle;
bmp: TBitmap;
memstream: TMemoryStream;
begin
bmp := TBitmap.Create;
bmp.LoadFromFile('icon.bmp');
bmp.Transparent := True;
bmp.TransparentColor := clGray;
Image1.Canvas.Draw(0, 0, bmp);
TrayIcon1.Icon.Transparent:=True;
TrayIcon1.Icon.TransparentColor:= clGray;
TrayIcon1.Icon.Assign(bmp);
TrayIcon1.Show;
bmp.Free;
end;
initialization
{$I unit1.lrs}
end.
Mantis conversion info:
- Mantis ID: 18651
- Version: 0.9.28.2