Page 1 of 1

SaveToStream and Transparency

Posted: Sun Feb 17, 2008 1:55 am
by 10546824
I can add a TTreeNode Shape
TTreeNodeShape.Image.Assign(SomeBitmap);
TTreeNodeShape.Image.Transparent:= true;
TTreeNodeShape.ImageAlignment:= iaCenter;

All is good , the image shows the background.
However if I

SaveTreeToStream(MyTree,strm)

or

SaveTreeToFile(MyTree,'C:\mytree')

and then reload the file or load it into a different TTree, the images loses the transparency and I see a white background around the images.

Any ideas?

Posted: Wed Feb 20, 2008 12:58 am
by Tom
Mmm, this looks like a bug. The only way to solve this issue at the moment is to set the transparent property back to true after loading the tree.

e.g. you could iterate the tree and set the transparent property of all nodes which have an image assigned to transparent = true;

as in :

Code: Select all

Procedure TForm2.SetTransparentToTrue(Sender:TTreeNodeShape);
begin
  if Assigned(sender.Image) and (Sender.ImageAlignment = iaCenter) then
    Sender.Image.Transparent := True;
end;


procedure TForm2.LoadTreeStreamClick(Sender: TObject);
var s: TFileStream;
begin
  Tree1.Clear;
  s := TFileStream.Create('c:\test.tree', fmOpenRead);
  try
    s.Position := 0;
    LoadTreeFromStream(TCustomTree(Tree1), s);
    Tree1.Roots.ForEach(SetTransparentToTrue);
    Tree1.Invalidate;
  finally
    FreeAndNil(s);
  end;
  Tree1.Color := clGreen;
end;